VISUALGO//PROBLEMS
minimum flips to make a or b equal to c · bit manipulationmedium
bit
·
flips
·
a
·
·
·
·
·
b
·
·
·
·
·
a | b
·
·
·
·
·
c
·
·
·
·
·
ELEMENTS
a
b
c
Python
def minFlips(a: int, b: int, c: int) -> int:
flips = 0
while a or b or c:
abit, bbit, cbit = a & 1, b & 1, c & 1
if cbit:
flips += int(not (abit or bbit))
else:
flips += abit + bbit
a, b, c = a >> 1, b >> 1, c >> 1
return flips