Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions number-of-1-bits/younlll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
# Time: O(log n) | Space: O(1)
def hammingWeight(self, n: int) -> int:
count = 0
while n:
count += n & 1
n >>= 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 비트연산자를 사용한 풀이가 문제에서 의도한 풀이인 것 같아 좋은 것 같습니다.
비트연산자의 존재는 알지만 잘 사용을 안하게 되는데 배워갑니다.


return count

19 changes: 19 additions & 0 deletions valid-palindrome/younlll.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 투 포인터를 활용한 풀이 잘 봤습니다! isalnum이라는 함수로 알파벳과 숫자만 걸러낼 수 있군요.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
# Time: O(n) | Space: O(1)
def isPalindrome(self, s: str) -> bool:
left, right = 0, len(s) - 1

while left < right:
while left < right and not s[left].isalnum():
left += 1
while left < right and not s[right].isalnum():
right -= 1

if s[left].lower() != s[right].lower():
return False

left += 1
right -= 1

return True

Loading