Skip to content

Commit dc79302

Browse files
Create minimum_domino_rotations.cpp
1 parent 2d992f4 commit dc79302

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

minimum_domino_rotations.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
int check(int x, vector<int>& A, vector<int>& B)
4+
{
5+
int a=0,b=0,k=0;
6+
for(int i=0;i<A.size();i++)
7+
{
8+
if(A[i]==x && B[i]==x)
9+
continue;
10+
k++;
11+
if(A[i]==x)
12+
a++;
13+
else if(B[i]==x)
14+
b++;
15+
else
16+
return -1;
17+
}
18+
return k-max(a,b);
19+
}
20+
int minDominoRotations(vector<int>& A, vector<int>& B) {
21+
int x=check(A[0],A,B);
22+
if(x==-1)
23+
return check(B[0],A,B);
24+
return x;
25+
}
26+
};

0 commit comments

Comments
 (0)