Java - check each number
java\nclass Solution {\n    public int minDominoRotations(int[] A, int[] B) {\n        int N = A.length;\n        int min = Integer.MAX_VALUE;\n        \n      
```java\nclass Solution {\n    public int minDominoRotations(int[] A, int[] B) {\n        int N = A.length;\n        int min = Integer.MAX_VALUE;\n        \n        for (int i = 1; i <= 6; i++) {\n            int j = 0;\n            int countA = 0;\n            int countB = 0;\n            \n            // Try make each number on A or B\n            while (j < N) {\n                if (A[j] != i && B[j] != i) {\n                    break;\n                }\n                if (A[j] != i && B[j] == i) {\n                    countA++;\n                }\n                \n                if (A[j] == i && B[j] != i) {\n                    countB++;\n                }\n                j++;              \n            }\n            if (j == N) {\n                min = Math.min(min, countA);\n                min = Math.min(min, countB);\n            }\n        }\n        \n        return min == Integer.MAX_VALUE ? -1 : min;\n    }\n    \n}\n```
[]