Skip to content

Commit b52033a

Browse files
authored
Create 1007. Minimum Domino Rotations For Equal Row (#785)
2 parents 34ea610 + 985d9d5 commit b52033a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {
4+
int n = tops.size();
5+
vector<int> top(7, 0), btm(7, 0), same(7, 0);
6+
for (int i = 0; i < n; i++) {
7+
top[tops[i]]++;
8+
btm[bottoms[i]]++;
9+
if (tops[i] == bottoms[i])
10+
same[tops[i]]++;
11+
}
12+
for (int num = 1; num <= 6; num++)
13+
if (top[num] + btm[num] - same[num] == n)
14+
return min(n - top[num], n - btm[num]);
15+
return -1;
16+
}
17+
};

0 commit comments

Comments
 (0)