-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1007.cpp
More file actions
36 lines (36 loc) · 1.01 KB
/
1007.cpp
File metadata and controls
36 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution {
public:
int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {
int res = INT_MAX;
int n = tops.size();
for (int target = 1; target <= 6; ++target) {
int cnt = 0;
bool flag = true;
for (int i = 0; i < n; ++i) {
if (tops[i] == target) continue;
else if (bottoms[i] == target) cnt++;
else {
flag = false;
break;
}
}
if (flag) {
res = min(res, cnt);
}
cnt = 0;
flag = true;
for (int i = 0; i < n; ++i) {
if (bottoms[i] == target) continue;
else if (tops[i] == target) cnt++;
else {
flag = false;
break;
}
}
if (flag) {
res = min(res, cnt);
}
}
return res == INT_MAX ? -1 : res;
}
};