less than 1 minute read

1318. Minimum Flips to Make a OR b Equal to c (medium)

class Solution:
    def minFlips(self, a: int, b: int, c: int) -> int:
        count = 0
        d = a | b
        if c == d:
            return 0
        while c or d:
            d = a | b
            if c & 1 == 1:
                if d & 1 == 0:
                    count += 1
            else:
                if a & 1 == 1:
                    count += 1
                if b & 1 == 1:
                    count += 1
            a >>= 1
            b >>= 1
            c >>= 1
        return count

2595. Number of Even and Odd Bits (easy)

class Solution:
    def evenOddBit(self, n: int) -> List[int]:
        res = [0, 0]
        count = 0
        while n:
            res[count % 2] += n & 1
            n >>= 1
            count += 1
        return res