Minimum Flips to Make a OR b Equal to c LeetCode solution in Java

1
class Solution {
2
public int minFlips(int a, int b, int c) {
3
int j = -1;
4
int x = a | b;
5
int count = 0;
6
while (c != 0 || x != 0) {
7
j++;
8
int aa = x % 2;
9
int bb = c % 2;
10
if (aa == 0 && bb == 1) count++;
11
else if (aa == 1 && bb == 0) count += funcount(j, a, b);
12
x = x >> 1;
13
c = c >> 1;
14
}
15

16
return count;
17
}
18

19
public static int funcount(int shift, int a, int b) {
20
int cc = 0;
21
int mask = 1 << shift;
22
int b1 = a & mask;
23
int b2 = b & mask;
24
if (b1 != 0) cc++;
25
if (b2 != 0) cc++;
26

27
return cc;
28
}
29
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0