Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
27 changes: 27 additions & 0 deletions combination-sum/dolphinflow86.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@DaleStudy/coach 주석에 복잡도 추가 완료

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.

좋아요! 주석에 복잡도 추가를 반영하신 내용 확인했습니다.

다음 팁을 참고하면 더 품질이 좋아집니다.

  • 복잡도 표기 위치: 함수 주석 바로 위나 코드 블록 위에 간단한 설명으로 남겨두고, 실제 구현부와 구분되게 작성하면 파트별 가독성이 올라갑니다.
  • 시간 복잡도 계산: 각 솔루션에 대해 일반적인 최악의 경우를 명시하고, 예외 케이스도 간략히 언급하면 리뷰어가 이해하기 쉽습니다.
  • 공간 복잡도: 재귀 깊이, 추가 자료구조 사용 여부를 각각 명시해 주세요.

질문이 있다면 어떤 파일의 주석 포맷이 리뷰어들에게 더 선명하게 다가오는지 함께 확인해드립니다.

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking
  • 설명: 코드가 모든 가능한 조합을 탐색하는 재귀 백트래킹으로 목표 합에 맞는 조합을 찾습니다. 가지치기 조건(remain < 후보값)으로 탐색 공간을 줄입니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N^(T/M)) O(k * C(n, k))
Space O(T/M) O(k)

피드백: 정렬된 후보를 이용해 남은 합이 현재 값보다 작아지면 가지치기를 수행한다. 재귀 경로의 길이를 저장하는 path와 답을 저장하는 answer의 공간이 주된 추가 공간이다.

개선 제안: 현재 구현이 적절해 보입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 1) Backtrack every possible combination to find subsets that match the target condition.
# TC: O(N^(T/M)) where N is the length of candidates, M is the minimum value in candidates, and T is the target number.
# SC: O(T/M) - The maximum depth of the recursion stack.
class Solution:
def backtrack(self, candidates: List[int], remain: int, start_index: int, path:List[int], answer: List[List[int]]):
if remain == 0:
answer.append(path[:])
return

cur = candidates[start_index]

for i in range(start_index, len(candidates)):
if remain < candidates[i]:
break

path.append(candidates[i])
self.backtrack(candidates, remain - candidates[i], i, path, answer)
path.pop()

def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
path = []
answer = []

candidates.sort()
self.backtrack(candidates, target, 0, path, answer)

return answer
11 changes: 11 additions & 0 deletions number-of-1-bits/dolphinflow86.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Bit Manipulation, Divide and Conquer
  • 설명: 주어진 코드는 이진법으로 자릿수를 확인해 1의 개수를 세는 방법으로, 비트를 다루는 Bit Manipulation 패턴과 수를 반으로 나누며 처리하는 Divide and Conquer 성격이 보인다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(logN) O(log n)
Space O(1) O(1)

피드백: 루프는 비트 길이만큼 실행되므로 시간은 로그 스케일이다. 초기값과 루프 조건을 단순화하면 좋다.

개선 제안: n을 비트 잉여 없이 고쳐 계산하는 내장 기법(예: Brian Kernighan's 알고리즘)으로 더 간결하게 만들 수 있다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 1) Divide by 2 and count set bit.
# TC: O(logN) where N is the given number.
# SC: O(1)
class Solution:
def hammingWeight(self, n: int) -> int:
setbit_count = 1

while n >= 2:
if n % 2 == 1: setbit_count += 1
n = n // 2
return setbit_count
42 changes: 42 additions & 0 deletions valid-palindrome/dolphinflow86.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers
  • 설명: 두 가지 구현 모두 투 포인터를 활용하여 문자열의 양쪽에서 문자들을 비교합니다. 첫 번째는 빈 문자열 제거 없이 인덱스를 이동하고, 두 번째는 필터링 후 새 문자열을 만들어 양끝 비교를 수행합니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: Solution.isPalindrome — Time: ✅ O(N) → O(n) / Space: ✅ O(1) → O(1)
유저 분석 실제 분석 결과
Time O(N) O(n)
Space O(1) O(1)

피드백: 두 구현 모두 필요 문자를 건너뛰고 비교하는 순서를 잘 다룬다. 공간은 상수다.

개선 제안: 필요 시 필터링 버전을 선택적 사용하도록 구조를 정리하면 코드 중복을 줄일 수 있다.

풀이 2: Solution.isPalindrome_filtered — Time: O(n) / Space: O(n)
복잡도
Time O(n)
Space O(n)

피드백: 추가 문자열 공간이 필요하지만 구현이 간결하다.

개선 제안: 공간 복잡도를 줄이려면 인덱스 방식의 양방향 탐색으로 구현하는 것이 좋다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 1) Iterate through the string using two-pointers, skipping non-alphanumeric characters and comparing them in lowercase to validate the palindrome in-place.
# TC: O(N) where N is the length of s
# SC: O(1)
class Solution:
def isPalindrome(self, s: str) -> bool:
left = 0
right = len(s) - 1

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

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

return True

# 2) Filter alphanumeric characters and conver them to lowercase to create a new string and then simply validate palindrome using two-pointers
# TC: O(N) where N is the length of s
# SC: O(N) where N is the length of s
class Solution:
def isPalindrome(self, s: str) -> bool:
new_str = ""
for ch in s:
if ch.isalnum():
new_str += ch.lower()

n = len(new_str)
left = 0
right = n - 1

while left < right:
if new_str[left] != new_str[right]: return False
left += 1
right -= 1

return True
Loading