java using majority vote O(n) time, O(1) space
\nclass Solution {\n    public int minDominoRotations(int[] A, int[] B) {\n        int aMajority = vote(A);\n        int bMajority = vote(B);\n        int a = c
```\nclass Solution {\n    public int minDominoRotations(int[] A, int[] B) {\n        int aMajority = vote(A);\n        int bMajority = vote(B);\n        int a = count(aMajority, A, B);\n        int b = count(bMajority, A, B);\n        if (a == -1) return b;\n        if (b == -1) return a;\n        return Math.min(a, b);\n    }\n    \n    private int vote(int[] A){\n        int m = A[0];\n        int cnt = 0;\n        for (int i = 1; i < A.length; i++){\n            if (cnt == 0) m = A[i];\n            else if (A[i] == m) cnt++;\n            else cnt--;\n        }\n        return m;\n    }\n    \n    private int count(int m, int[] A, int[] B){\n        int cnt = 0;\n        int pair = 0;\n        for (int i = 0; i < A.length; i++){\n            if(A[i] != m && B[i] != m) return -1;\n            else if (A[i] == m && B[i] == m) pair++;\n            else if (A[i] == m) cnt++;\n        }\n        return Math.min(cnt, A.length - pair - cnt);\n    } \n}\n```
[]