2220. Minimum Bit Flips to Convert Number
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 88% Topics: Bit Manipulation
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(logn)
# Space: O(1)
# bit manipulation
class Solution(object):
def minBitFlips(self, start, goal):
"""
:type start: int
:type goal: int
:rtype: int
"""
return bin(start^goal).count('1')
Solution from kamyu104/LeetCode-Solutions · MIT