C++ super-simple and easy short explained solution, O(n) time, O(1) space
\nclass Solution {\npublic:\n    int countDifference(vector<int>& A, vector<int>& B, int num) {\n        int countA = 0, countB = 0;\n        \n        for (int
```\nclass Solution {\npublic:\n    int countDifference(vector<int>& A, vector<int>& B, int num) {\n        int countA = 0, countB = 0;\n        \n        for (int i=0; i<A.size(); i++) {\n            // if we have a domino which doesn\'t have num at all, num can\'t be the whole row:\n            if ((A[i] != num) && (B[i] != num))\n                return -1;\n            if (A[i] != num) countA++;\n            if (B[i] != num) countB++;\n        }\n        \n        return min(countA, countB);\n    }\n    \n    int minDominoRotations(vector<int>& A, vector<int>& B) {\n        // first try to make A[0] the whole row, then try B[0]:\n        int res1 = countDifference(A, B, A[0]);\n        int res2 = countDifference(A, B, B[0]);\n        \n        return min(res1, res2) > 0 ? min(res1, res2):max(res1, res2);\n    }\n};\n```\n**Like it? please upvote...**
['C']