Skip to content

Commit b05efb8

Browse files
authored
Create number-of-even-and-odd-bits.py
1 parent 44eb711 commit b05efb8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Python/number-of-even-and-odd-bits.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
# bit manipulation
5+
class Solution(object):
6+
def evenOddBit(self, n):
7+
"""
8+
:type n: int
9+
:rtype: List[int]
10+
"""
11+
def popcount(x):
12+
return bin(x)[2:].count('1')
13+
14+
return [popcount(n&0b0101010101), popcount(n&0b1010101010)]

0 commit comments

Comments
 (0)