2595. Number of Even and Odd Bits
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 73% Topics: Bit Manipulation
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(1)
# Space: O(1)
# bit manipulation
class Solution(object):
def evenOddBit(self, n):
"""
:type n: int
:rtype: List[int]
"""
def popcount(x):
return bin(x)[2:].count('1')
return [popcount(n&0b0101010101), popcount(n&0b1010101010)]
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions