Easy to understand solution with explanation
\nclass Solution {\npublic:\n    \n    int countdiff(vector<int>&tops, vector<int>&bottoms, int num){\n        int counttops=0,countbot=0;\n        for(int i=0;
```\nclass Solution {\npublic:\n    \n    int countdiff(vector<int>&tops, vector<int>&bottoms, int num){\n        int counttops=0,countbot=0;\n        for(int i=0;i<tops.size();i++){\n            //to check if the num we are passing exist in all dominoes\n            if(tops[i]!=num && bottoms[i]!=num)return -1;\n            if(tops[i]!=num)counttops++;\n            if(bottoms[i]!=num)countbot++;\n        }\n        return min(counttops,countbot);\n    }\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        \n        int res1 = countdiff(tops,bottoms,tops[0]);\n        int res2 = countdiff(tops,bottoms,bottoms[0]);\n        //if res is less than 0 then return max to get positive value\n        return(min(res1,res2)<0)?max(res1,res2):min(res1,res2);\n    }\n};\n```
['C', 'C++']