[Java] O(n)/O(1) time/space beats 99.7%
\nclass Solution {\n    int min = Integer.MAX_VALUE;\n    public int minDominoRotations(int[] A, int[] B) {\n        minDominoRotations(A,B,A[0]); \n        min
```\nclass Solution {\n    int min = Integer.MAX_VALUE;\n    public int minDominoRotations(int[] A, int[] B) {\n        minDominoRotations(A,B,A[0]); \n        minDominoRotations(A,B,B[0]); \n        minDominoRotations(B,A,A[0]);\n        minDominoRotations(B,A,B[0]);\n        return min==Integer.MAX_VALUE?-1:min;\n    }\n    \n    public void minDominoRotations(int[] A, int[] B, int n) {\n        int sum = 0;\n        for (int i=0;i<A.length;i++){\n            if (A[i]!=n && B[i]!=n)return;\n            else if (A[i]!=n && B[i]==n)sum++;\n        }\n        min = Math.min(min, sum);\n    }\n}\n```
[]