[Python] Top down DP - Clean & Concise
Solution 1: Top down DP\n\nclass Solution:\n    def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n        @lru_cache(None)\n        def dp(i, isSwa
**Solution 1: Top down DP**\n```\nclass Solution:\n    def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n        @lru_cache(None)\n        def dp(i, isSwap):\n            if i == len(nums1):\n                return 0\n            \n            cand = []\n            if i == 0:\n                last1 = last2 = -math.inf\n            elif isSwap:\n                last1, last2 = nums2[i-1], nums1[i-1]\n            else:\n                last1, last2 = nums1[i-1], nums2[i-1]\n                \n            if nums1[i] > last1 and nums2[i] > last2:\n                cand.append(dp(i+1, False))  # Case 1: Dont swap\n            if nums2[i] > last1 and nums1[i] > last2:\n                cand.append(dp(i+1, True) + 1)  # Case 2: Swap\n            \n            return min(cand) if cand else math.inf\n        \n        return dp(0, False)\n```\nComplexity:\n- Time: `O(4 * N)`, where `N <= 10^5` is length of `nums1` or `nums2`.\n- Space: `O(2 * N)`
[]