Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9611004

Browse files
author
Victor
authored
fixed a bug.
1 parent 61d7644 commit 9611004

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

‎1007. Minimum Domino Rotations For Equal Row.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,36 @@ In this case, it is not possible to rotate the dominoes to make one row of value
4141

4242

4343
int minDominoRotations(int* A, int ASize, int* B, int BSize){
44-
int i, a_up, a_down, b_down, b_up;
4544
bool a_ok, b_ok;
45+
int i, a_up, a_down, b_down, b_up;
4646

4747
a_ok = b_ok = true;
4848
a_up = a_down = b_down = b_up = 0;
4949

50-
for (i = 0; i < ASize &&
51-
(a_ok && (A[i] == A[0] || B[i] == A[0])) ||
52-
(b_ok && (B[i] == B[0] || A[i] == B[0])); i ++) {
50+
for (i = 0; i < ASize; i ++) {
5351
if (a_ok && A[i] != A[0] && B[i] != A[0]) a_ok = false;
5452
if (b_ok && B[i] != B[0] && A[i] != B[0]) b_ok = false;
53+
54+
if (!a_ok && !b_ok) return -1;
55+
5556
if (a_ok) {
56-
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
57-
if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
57+
if (A[i] != A[0]) a_up ++; // flip up to make all are A[0] on top
58+
if (B[i] != A[0]) a_down ++; // flip down to make all are A[0] in bottom
5859
}
5960
if (b_ok) {
6061
if (B[i] != B[0]) b_down ++;
6162
if (A[i] != B[0]) b_up ++;
6263
}
63-
//printf("%d: a=%d, b=%d\n", i, a, b);
64-
}
65-
if (a_ok && i == ASize) return a_up < a_down ? a_up : a_down;
66-
if (b_ok && i == ASize) return b_up < b_down ? b_up : b_down;
67-
return -1;
68-
/*
69-
if (i == ASize) return a < b ? a : b;
70-
a = b = 0;
71-
for (i = 0; i < ASize && (B[i] == B[0] || A[i] == B[0]); i ++) {
72-
if (B[i] != B[0]) b ++;
73-
if (A[i] != B[0]) a ++;
74-
//printf("%d: a=%d, b=%d\n", i, a, b);
7564
}
76-
if (i == ASize) return a < b ? a : b;
7765

78-
//printf("a:%d, b:%d\n", a, b);
66+
if (a_ok) returna_up<a_down ? a_up : a_down;
7967

80-
return -1;*/
68+
if (b_ok) return b_up < b_down ? b_up : b_down;
69+
70+
return -1;
8171
}
8272

8373

84-
8574
/*
8675
Difficulty:Medium
8776

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /