very easy to understand python solution
\nclass Solution(object):\n    def minSwap(self, A, B):\n        """\n        :type A: List[int]\n        :type B: List[int]\n        :rtype: int\n        """\n
```\nclass Solution(object):\n    def minSwap(self, A, B):\n        """\n        :type A: List[int]\n        :type B: List[int]\n        :rtype: int\n        """\n        \n        keep=[float(\'inf\') for i in range(len(A))]\n        swap=[float(\'inf\') for i in range(len(A))]\n        \n        # first element you can either keep it or swap it\n        keep[0]=0\n        swap[0]=1\n        \n        for i in range(1,len(A)):\n            if A[i]>A[i-1] and B[i]>B[i-1]:\n                keep[i]=min(keep[i-1],keep[i])\n            if A[i]>B[i-1] and B[i]>A[i-1]:\n                keep[i]=min(keep[i],swap[i-1])\n            if A[i]>B[i-1] and B[i]>A[i-1]:    \n                swap[i] =min(keep[i-1]+1,swap[i])\n            if A[i]>A[i-1] and B[i]>B[i-1]:\n                swap[i] =min(swap[i-1]+1,swap[i])\n        return min(swap[-1],keep[-1])\n```
[]