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
20 changes: 20 additions & 0 deletions climbing-stairs/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Hash Map / Hash Set, Backtracking
  • 설명: 재귀와 메모이제이션으로 중복 계산을 줄여 문제를 풀이하며, 결과를 저장하는 해시 맵을 사용한다. 부분 해를 합쳐 전체 해를 구하는 DP 스타일 접근으로 패턴에 부합하고, 탐색 과정에서 상태를 저장한다.

📊 시간/공간 복잡도 분석

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

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

피드백: 메모화를 사용해 중복 계산을 피하고 재귀 깊이는 n까지 증가한다.

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

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

피드백: 왼쪽/오른쪽 누적곱을 순회하며 결과 배열에 누적한다.

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

풀이 3: Solution.isAnagram (전 첫 구현) — Time: ❌ O(N) → O(n log n) / Space: ✅ O(N) → O(n)
유저 분석 실제 분석 결과
Time O(N) O(n log n)
Space O(N) O(n)

피드백: 정렬에 의한 시간 복잡도 증가가 존재한다.

개선 제안: 필요 시 카운트(Hashmap) 기반으로 평균 O(n) 가능.

풀이 4: Solution.isAnagram (두 번째 구현) — Time: O(n) / Space: O(k)
복잡도
Time O(n)
Space O(k)

피드백: 해시맵으로 선형 시간에 해결 가능하다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 1) Recursion with memoization.
# TC: O(N) where N is the given natural number.
# SC: O(N) where N is the given natural number.
class Solution:
def climb_rec(self, n: int, step: int, memo: Dict[int, int]):
if step > n: return 0
if step in memo: return memo[step]
if step == n: return 1

first_way = self.climb_rec(n, step + 1, memo)
second_way = self.climb_rec(n, step + 2, memo)
memo[step] = first_way + second_way
return memo[step]


def climbStairs(self, n: int) -> int:
if n == 1: return 1

memo = {}
return self.climb_rec(n, 1, memo) + self.climb_rec(n, 2, memo)
20 changes: 20 additions & 0 deletions product-of-array-except-self/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, Greedy, Hash Map / Hash Set, Dynamic Programming, Divide and Conquer, Bit Manipulation, Binary Search, Monotonic Stack, Trie, Union Find, BFS, DFS, Backtracking, Heap / Priority Queue
  • 설명: 이 코드는 왼쪽 곱과 오른쪽 곱을 미리 계산해 전체 곱을 구하는 방식으로 단일 패스가 아닌 두 패스를 이용하는 포맷이며, 추가로 곱셈의 중간값을 유지하면서 결과를 갱신한다. 두 포인터 스타일의 순회와 누적 값을 활용하는 패턴으로 간주될 수 있다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 1) Without using division operator and need to meet linear time complexity,
# calculate left accumulated product and calculate right accumulated product except iself and then
# product of left and right to get the result.
# TC: O(N) where N is the length of nums
# SC: O(N) where N is the length of nums
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
n = len(nums)
answer = [1] * n
acc = 1
for i in range(1, n):
acc *= nums[i-1]
answer[i] = acc

acc = 1
for i in range(n-2, -1, -1):
acc *= nums[i+1]
answer[i] *= acc

return answer
25 changes: 25 additions & 0 deletions valid-anagram/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Sort or Count
  • 설명: 주어진 코드에서 두 문자열의 요소를 비교하기 위해 해시 맵으로 문자 등장 횟수를 세고 감소시키는 방식(H using Hash Map)과 정렬 후 비교하는 방식(정렬 기반 비교)이 사용됩니다. 패턴 목록에는 Hash Map / Hash Set이 명시되어 있고, 정렬 기반 접근은 패턴 목록의 정확한 항목에 부합하는 명칭이 없어 포함 여부를 판단해야 할 경우 Hash Map 패턴으로 주로 설명합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 1) Sort input strings and check if those are the same.
# TC: O(NlogN) where N is the size of string s and t due to sorting
# SC: O(N) where N is the length of string s and t to store sorted list.
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
return sorted(s) == sorted(t)

# 2) Using dict to store count of the first string and decrease back to see if there's negative count.
# TC: O(N + M) where N is the length of s and M is the length of t.
# SC: O(N + M) where N is the length of s and M is the length of t.
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if len(s) != len(t): return False

char_map: Dict[str, int] = {}
for ch in s:
char_map[ch] = char_map.get(ch, 0) + 1

for ch in t:
if ch not in char_map or char_map[ch] == 0:
return False

char_map[ch] -= 1

return True
Loading