-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
37 lines (34 loc) · 879 Bytes
/
main.cpp
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
37
class Solution {
public:
int minFlips(int a, int b, int c) {
int result = 0;
for (int i = 0; i < 32; ++i) {
int mask = 1 << i;
bool aa = a & mask;
bool bb = b & mask;
if (c & mask) {
if (aa || bb) continue;
++result;
} else {
if (!aa && !bb) continue;
result += aa + bb;
}
}
return result;
}
};
class Solution {
public:
int minFlips(int a, int b, int c) {
int result = 0;
for (int i = 0; i < 32; ++i) {
int mask = 1 << i;
bool aBit = a & mask;
bool bBit = b & mask;
bool cBit = c & mask;
if ((aBit || bBit) == cBit) continue;
result += cBit ? 1 : aBit + bBit;
}
return result;
}
};