HTMLify

LootCode - Minimum Bit Flips to Convert Number - Python
Views: 31 | Author: abh
class Solution:
    def minBitFlips(self, start: int, goal: int) -> int:
        bb = len(bin(max([start, goal]))) - 2
        sb = bin(start)[2:].zfill(bb)
        gb = bin(goal)[2:].zfill(bb)
        d = 0
        for i in range(bb):
            if sb[i] != gb[i]:
                d += 1
        return d

Comments