Skip to content

Commit 622de8e

Browse files
committed
hammingWeight - AC
1 parent cbde2bb commit 622de8e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/python3
2+
# -*- coding: utf-8 -*-
3+
'''
4+
AC
5+
'''
6+
7+
#import time
8+
from math import *
9+
10+
class Solution(object):
11+
def hammingWeight(self, n):
12+
"""
13+
:type n: int
14+
:rtype: int
15+
"""
16+
return bin(n).count('1')
17+
18+
if __name__ == "__main__":
19+
20+
#t0 = time.perf_counter()
21+
testlist=[0,1,3,128]
22+
test=Solution()
23+
for i in testlist:
24+
print(test.hammingWeight(i))
25+
26+
#print(time.perf_counter() - t0)
27+
28+
29+
'''
30+
31+
'''

0 commit comments

Comments
 (0)