-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode1318.cpp
More file actions
37 lines (37 loc) · 799 Bytes
/
LeetCode1318.cpp
File metadata and controls
37 lines (37 loc) · 799 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
27
28
29
30
31
32
33
34
35
36
37
class Solution
{
public:
int checkOdd(int n)
{
return (n & 1);
}
int minFlips(int a, int b, int c)
{
int flip = 0;
while (a > 0 or b > 0 or c > 0)
{
if (c & 1)
{
if (checkOdd(a) == 0 and checkOdd(b) == 0)
{
flip++;
}
}
else
{
if (checkOdd(a) == 1 and checkOdd(b) == 1)
{
flip += 2;
}
else if (checkOdd(a) == 1 or checkOdd(b) == 1)
{
flip += 1;
}
}
a >>= 1;
b >>= 1;
c >>= 1;
}
return flip;
}
};