Java, check A[0] and B[0], easy to understand
The idea is pretty straightforward, we check if we can make a row for A[0] and B[0]. \nReturn min rotations needed to make A[0] or B[0] answer, or return -1 if 
The idea is pretty straightforward, we check if we can make a row for A[0] and B[0]. \nReturn min rotations needed to make A[0] or B[0] answer, or return -1 if can\'t make any of them.  \n\n```\npublic int minDominoRotations(int[] A, int[] B) {\n        if (A == null || B==null || A.Length != B.length)\n            return -1;\n        \n        int top = minRotationsForTarget(A, B, A[0]); //count rotations to make A[0] row\n        int bottom = minRotationsForTarget(A, B, B[0]);//count rotations to make B[0] row\n        \n        if (top == -1 && bottom == -1) return -1; //can\'t make row for both A[0] and B[0] -> no answer, return -1\n        if (top == -1) return bottom;\n        else if (bottom == -1) return top;\n        \n        return Math.min(top, bottom);     \n    }\n    \n    int minRotationsForTarget(int[] A, int B[], int target){\n        //initialize the counters for rotations defaulted to the count of domino\n        int top = A.length;\n        int bottom = A.length;\n        \n        for (int i = 0; i<A.length; i++){\n            if (A[i] != target && B[i] != target) return -1; //can\'t make answer for this target value\n            \n            if (A[i] == target) top--; //target value is already in place, no need to rotate for top row\n            if (B[i] == target) bottom--; //no need to rotate for bottom row\n        }\n        \n        return Math.min(top, bottom); \n    }\n```\n\nTime complexity is O(A+B), Space complexity is O(1)
[]