Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions number-of-1-bits/yayyz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# bit operation
class Solution:
def hammingWeight(self, n: int) -> int:
count = 0
while n:
count += n & 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 and 연산을해서 값이 있으면 count 값을 증가시켰는데, 생각해보니 and 연산 값 자체를 더해도 되겠네요.
한 수 배우고 갑니다.

n >>= 1
return count

# class Solution:
# def hammingWeight(self, n: int) -> int:
# return bin(n).count('1')
15 changes: 15 additions & 0 deletions valid-palindrome/yayyz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution:
def isPalindrome(self, s: str) -> bool:
s = ''.join(filter(str.isalnum, s)).lower()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사전에 alpha-numeric 값들만 필터링을 해두는 방법도 좋은 방법 같습니다.
filter 함수를 써보지 못했는데, 적용하신 코드를 참고해서 나중에 써볼 수 있을 것 같습니다. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조언 감사합니다 :)

if not (s and s.strip()): return True

head = 0
tail = len(s) -1
while head < tail:
if s[head] != s[tail]:
return False
else:
head += 1
tail -= 1

return True