C++ solution
\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& A, vector<int>& B) {\n        int res = check(A, B, A[0]);\n        return (res != -1) ? re
```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& A, vector<int>& B) {\n        int res = check(A, B, A[0]);\n        return (res != -1) ? res : check(A, B, B[0]);\n    }\nprivate:\n    int check(vector<int>& A, vector<int>& B, int val) {\n        int a = 0, b = 0;\n        for (int i = 0; i < A.size(); i++) {\n            if (A[i] != val && B[i] != val)\n                return -1;\n            else if (A[i] != val)\n                a++;\n            else if (B[i] != val)\n                b++;\n        }\n        return min(a, b);\n    }\n};\n```
['C', 'C++']