Python 3 solution faster than 98.46%
\nclass Solution:\n    def helper(self, A, B):\n        first, count1 = A[0], 0\n        for i in range(1, len(A)):\n            if A[i] != first:\n            
```\nclass Solution:\n    def helper(self, A, B):\n        first, count1 = A[0], 0\n        for i in range(1, len(A)):\n            if A[i] != first:\n                if B[i] != first:\n                    count1 = None\n                    break\n                else:\n                    count1 += 1\n        count2 = 0\n        if A[0] != B[0]:\n            first = B[0]\n            for i in range(len(A)):\n                if A[i] != first:\n                    if B[i] != first:\n                        count2 = None\n                        break\n                    else:\n                        count2 += 1\n        else:\n            count2 = count1\n        if not count1 and not count2:            \n            return -1\n        if count1 and count2:\n            return min(count1, count2)\n        if count1:\n            return count1\n        return count2\n    \n    def equal(self, arr):\n        temp = arr[0]\n        for i in range(1, len(arr)):\n            if arr[i] != temp:\n                return False\n        return True\n        \n    def minDominoRotations(self, A: List[int], B: List[int]) -> int:\n        if self.equal(A) or self.equal(B):\n            return 0\n        first, second = self.helper(A, B), self.helper(B, A)\n        if first and second:\n            return min(first, second)\n        if first:\n            return first\n        return second\n```
['Python', 'Python3']