forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1007.cpp
More file actions
26 lines (25 loc) · 724 Bytes
/
1007.cpp
File metadata and controls
26 lines (25 loc) · 724 Bytes
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
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int minDominoRotations(vector<int>& A, vector<int>& B)
{
int a = 0, b = 0, n = A.size();
for (int i = 0; i < n; ++i)
{
if (A[i] != A[0] and B[i] != A[0]) break;
if (A[i] != A[0]) a++;
if (B[i] != A[0]) b++;
if (i == n - 1) return min(a, b);
}
a = 0, b = 0;
for (int i = 0; i < n; ++i)
{
if (A[i] != B[0] and B[i] != B[0]) break;
if (A[i] != B[0]) a++;
if (B[i] != B[0]) b++;
if (i == n - 1) return min(a, b);
}
return -1;
}
};