Skip to content
23 changes: 23 additions & 0 deletions climbing-stairs/Chanz82.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Memoization, Divide and Conquer
  • 설명: 해당 코드는 피보나치 계열의 점화식을 동적계획법으로 풀고, 중간 결과를 저장해 재계산을 피하는 형태로 작성되어 있습니다. 메모이제이션을 통해 중복 계산을 방지하며, 재귀 분할로 문제를 해결합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 각 n에 대해 한 번씩 계산하고 결과를 메모에 저장하므로 시간은 선형이며, 재귀 깊이는 n까지 가능해 공간도 선형이다.

개선 제안: 호출 깊이에 따른 스택 사용을 피하고 반복/탐색으로 변환하면 스택 오버플로를 줄일 수 있다.

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

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.

공간복잡도 맞긴 하신데, 재귀를 하면 메모리 스택에 Function call이 계속 쌓이기 때문에 배열을 쓰는것보단 좋진 않을거에요!

쉬운것부터 바텀업으로 구현하시는것도 저는 DP를 공부하기 좋은 선택이라고 생각합니다.

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.

아아 그러네요 스택 메모리도 감안을 해야 하는군요.. n이 커지면 메모리 점유가 엄청나게 많아지겠군요..!
좋은 인사이트 감사합니다!! 👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

저도 앞에 피드백 주신 분과 같이 n이 커지면 recursion error가 날 수 도 있을 거 같아서 바텀업 구현을 고려해보시는 것도 좋을 거 같다는 의견입니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:

def __init__(self):
self.memo = dict()

def climbStairs(self, n: int) -> int:

# 공간복잡도 : n의 개수 만큼 memo가 할당되므로 o(n)
# 시간복잡도 : 각 칸에 대해서 계산이 1번씩만 되므로 o(n)

# base
if n <= 2 :
return n

# 이미 계산 한 값이라면 반환
if n in self.memo:
return self.memo[n]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이미 계산했던 값인지 체크하고 바로 반환해 주는거 좋은 거 같아요!


# 1칸 전과 2칸 전의 결과를 합한 것을 반환.
result = self.climbStairs(n-2) + self.climbStairs(n-1)
self.memo[n] = result

return result
16 changes: 16 additions & 0 deletions product-of-array-except-self/Chanz82.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, Dynamic Programming, Hash Map / Hash Set, Greedy, Divide and Conquer, Binary Search, Monotonic Stack, Breadth-First Search, Depth-First Search, Backtracking, Union Find, Trie, Bit Manipulation, Heap / Priority Queue
  • 설명: 주어진 해결책은 각 위치의 곱을 좌우 누적 곱으로 구하는 방식으로, 중간에 보조 배열(left, right)을 사용해 결과를 얻는 구조이다. 이는 배열 기반의 누적 결과를 이용하는 패턴으로, 난이도는 DP적 사고와 함께 부분 문제를 결합한다는 점에서 Dynamic Programming의 applying 형태로 해석할 수 있다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 추가 배열 left와 right를 사용해 각 원소에 대해 O(1) 추가 연산으로 결과를 얻는다.

개선 제안: 추가 공간 없이 결과 배열 하나만 사용하도록 압축 가능하다.

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

@alphaorderly alphaorderly Jul 3, 2026

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.

Follow up 에 공간복잡도 O(1)로 해결해 보라는게 있어서요 ( 출력 배열 1개 제외 )

한번 시도해 보시는것도 좋을것 같아요!

힌트는 left, right 이 두개는 사실 배열이 아니여도 됩니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:

# 공간 복잡도 : 2개의 list를 사용하므로 O(2n)=O(n)
# 시간 복잡도 : nums를 세번 순회 o(n)
n = len(nums)
left = [1] * n
right = [1] * n

for idx in range(1, n):
left[idx] = left[idx-1] * nums[idx-1]

for idx in range(n-2, -1, -1):
right[idx] = right[idx+1] * nums[idx+1]

return [left[i] * right[i] for i in range(n)]
19 changes: 19 additions & 0 deletions valid-anagram/Chanz82.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Two Pointers
  • 설명: 두 문자열의 문자가 같은지 확인하기 위해 문자 빈도수를 해시맵으로 세고, t의 문자가 나타날 때마다 감소시키며 남은 개수를 확인합니다. 해시맵을 이용한 카운팅 방식은 패턴으로 분류되고, 두 문자열의 합치면서 비교하는 흐름이 포함되어 있어 두 패턴으로 간주합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n + m)
Space O(k)

피드백: 두 문자열 길이에 비례하는 선형 시간과 알파벳 크기에 비례하는 공간을 사용한다.

개선 제안: 모든 문자가 ASCII인 경우 배열 인덱스 기반 구현으로 상수 공간에 근접 가능하다.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

처음에 string s랑 string t랑 길이가 다르면 반복문을 아예 돌지 않고 바로 false를 반환하는 base가 있으면 더 좋을 거 같아요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
hashmap = dict()

# 공간복잡도 : hashmap을 사용하므로 공간복잡도는 O(N)입니다.
# 시간복잡도 : 문자열 s의 길이만큼 한번 순회하고, 다시 문자열 t의 길이만큼 순회하므로 O(s+t) => O(N)입니다.
for ch in s:
hashmap[ch] = hashmap.get(ch, 0) + 1

for ch in t:
if ch in hashmap:
hashmap[ch] -= 1
if hashmap[ch] == 0:
del hashmap[ch]
else:
return False

return not hashmap

Loading