Skip to content
Merged
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
15 changes: 15 additions & 0 deletions combination-sum/Seoya0512.py
Copy link
Contributor

Choose a reason for hiding this comment

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

저도 해설 보면서 풀이를 하였는데, 쉽지 않았습니다. 스스로 생각하고 풀이를 작성한 것에 박수 드리고 싶습니다. 👏

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'''
Approach
- target값에서 candidate 값을 빼고 그 누적합을 사용해야한다는 흐름은 파악했지지만 구현이 어려웠습니다.
-그래서 알고달레를 참고해서 최대한 이해하고 혼자 작성해보려고 했습니다....
'''
class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
dp = [[] for _ in range(target + 1)]
dp[0] = [[]]

for candidate in candidates:
for num in range(candidate, target +1):
for combination in dp[num - candidate]:
dp[num].append(combination + [candidate])
return dp[target]
20 changes: 20 additions & 0 deletions number-of-1-bits/Seoya0512.py
Copy link
Contributor

Choose a reason for hiding this comment

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

깔끔합니다! 👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'''
Approach
- 십진법을 이진법으로 변환하는 방식과 누적합을 사용함

Time Complexity: O(log n)
- while 문에서 숫자(num)을 계속해서 2로 나누는데 소요되는 시간

Space Complexity: O(1)
- 상수 bits와 nums를 저장하는 공간
'''
class Solution:
def hammingWeight(self, n: int) -> int:
bits = 0
# 주어진 숫자를 2로 나눈 나머지 값이 1인 경우 bits에 누적함
num = n
while num != 0 :
if num % 2 == 1 :
bits += 1
num //= 2
return bits
23 changes: 23 additions & 0 deletions valid-palindrome/Seoya0512.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'''
Approach
- 파이썬에서 제공되는 메소드를 사용해서 문자열 필터링 처리후 왼쪽과 오른쪽 값을 비교

Time Complexity: O(N)
- 문자열 s의 길이를 N이라고 할 때, 문자열을 순회하며 필터링하는 데 O(N) 시간이 걸림
- 이후 필터링된 문자열을 뒤집어 right 값을 만드는 데도 O(N) 시간이 걸림
- left와 right 값을 비교하는 데도 O(N) 시간이 걸림

Space Complexity: O(N)
- 필터링된 문자열을 저장하는 데 O(N) 공간이 필요함
- left와 right 값을 저장하는 데도 각각 O(N) 공간이 필요함
'''
class Solution:
def isPalindrome(self, s: str) -> bool:
# 문자열이 아닌 경우만 소문자 변환 필터링
char_str = [char.lower() for char in s if char.isalnum()]
# 왼쪽 값
left = ''.join(char_str)
# 오른쪽 값
right = ''.join(char_str[::-1])

return left == right