Bit Manipulation Python Leetcode Question