blob: 6b5da6fa8ab61fd94d3c7fcf374e3ae82c4da1a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# 2220. Minimum Bit Flips to Convert Number
"""
a bit flip of a number 'x' is choosing a bit in the binary representation of
'x' and flipping it from either 0 to 1 or 1 to 0. given two integers 'start'
and 'goal', return the minimum number of bit flips to convert 'start' to
'goal'.
"""
class Solution(object):
def minBitFlips(self, start, goal):
"""
:type start: int
:type goal: int
:rtype: int
"""
return (start ^ goal).bit_count()
if __name__ == "__main__":
obj = Solution()
print(obj.minBitFlips(10, 7))
print(obj.minBitFlips(3, 4))
|