Clean Python Solution (With Other Similar Problems)
python\nclass Solution(object):\n    def minSwap(self, A, B):\n        keep = [float(\'inf\') for _ in xrange(len(A))]\n        swap = [float(\'inf\') for _ in 
```python\nclass Solution(object):\n    def minSwap(self, A, B):\n        keep = [float(\'inf\') for _ in xrange(len(A))]\n        swap = [float(\'inf\') for _ in xrange(len(A))]\n        \n        keep[0] = 0\n        swap[0] = 1\n        \n        for i in xrange(1, len(A)):\n            \n            if A[i]>A[i-1] and B[i]>B[i-1]:\n                keep[i] = keep[i-1]\n                swap[i] = swap[i-1]+1\n                \n            if A[i]>B[i-1] and B[i]>A[i-1]:\n                keep[i] = min(keep[i], swap[i-1])\n                swap[i] = min(swap[i], keep[i-1]+1)\n                \n        return min(keep[-1], swap[-1])\n"""\nSimilar Problems: 198, 213, 309, 740, 790, 801\nFor more other topics similar problems, check out my GitHub.\nIt took me a lots of time to make the solution. Becuase I want to help others like me.\nPlease give me a star if you like it. Means a lot to me.\nhttps://github.com/wuduhren/leetcode-python\n"""\n```
[]