2220. Minimum Bit Flips to Convert Number

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2220

class Solution:
    def minBitFlips(self, start: int, goal: int) -> int:
        t = start ^ goal
        res = 0
        while t:
            res += t & 1
            t >>= 1
        return res