mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
22 lines
451 B
C#
22 lines
451 B
C#
|
public class Solution {
|
||
|
public int MinFlips(int a, int b, int c) {
|
||
|
var flips = 0;
|
||
|
|
||
|
for (; (a | b) != c; a >>= 1, b >>= 1, c >>= 1) {
|
||
|
var (aa, bb, cc) = (a & 1, b & 1, c & 1);
|
||
|
|
||
|
if ((aa | bb) == cc) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (aa != 0 && bb != 0) {
|
||
|
flips += 2;
|
||
|
} else {
|
||
|
++flips;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return flips;
|
||
|
}
|
||
|
}
|