Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
13 changes: 13 additions & 0 deletions number-of-1-bits/hyogshin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'''
풀이
- 파이썬3 내장 함수인 bit_count() 함수 이용
시간 복잡도: O(1)
공간 복잡도: O(1)
'''

class Solution:
def hammingWeight(self, n: int) -> int:
return n.bit_count()

27 changes: 27 additions & 0 deletions valid-palindrome/hyogshin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'''
풀이
- alphanumeric만 저장하는 alnum 배열 생성
- alnum 배열의 절반 (소수점 버림) 길이를 순회하며 Palindrome 인지 확인

시간 복잡도: O(n)
- for loop * 2 -> O(2n) => O(n)

공간 복잡도: O(n)
- alphanumeric만 저장하는 alnum 배열이 최악의 경우 O(n) 일 수 있음
'''

class Solution:
def isPalindrome(self, s: str) -> bool:
alnum = []
is_pal = True
for c in s:
Copy link
Contributor

Choose a reason for hiding this comment

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

-> alnum = [c.lower() for c in s if c.isalnum()]처럼 한 줄로 간결하게 작성 가능

if c.isalnum():
alnum.append(c.lower())

for c in range(len(alnum) // 2):
if alnum[c] != alnum[-1 - c]:
is_pal = False
break

return is_pal
Copy link
Contributor

Choose a reason for hiding this comment

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

is_pal 변수를 쓰지 않고 불일치 시 바로 return False를 하고 마지막에 return True만 남기면 더 간단해집니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

더 간단한 방법이 있었네요!


Loading