HTMLify

LeetCode - Number of Even and Odd Bits - Python
Views: 12 | Author: abh
class Solution:
    def evenOddBit(self, n: int) -> List[int]:
        ans = [0, 0]
        for i, v in enumerate(bin(n)[2:][::-1]):
            if v == "0":
                continue
            if i%2:
                ans[1] += 1
            else:
                ans[0] += 1
        return ans

Comments