Skip to content

Commit 3673158

Browse files
committed
[:solved] two problems
1 parent 840701f commit 3673158

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

number-of-1-bits/ppxyn1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# idea: -
2+
3+
from collections import Counter
4+
class Solution:
5+
def hammingWeight(self, n: int) -> int:
6+
bits = bin(n).split('0b')[-1]
7+
return Counter(bits)['1']
8+
9+
10+

valid-palindrome/ppxyn1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# idea : regex
2+
import re
3+
4+
class Solution:
5+
def isPalindrome(self, s: str) -> bool:
6+
alphabet = re.sub(r'[^A-Za-z0-9]', '', s).lower()
7+
8+
return alphabet == alphabet[::-1]
9+
10+
11+

0 commit comments

Comments
 (0)