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
12 changes: 12 additions & 0 deletions climbing-stairs/njngwn.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
  • 설명: 피보나치-like 점화식으로 하위 문제의 해를 순차적으로 계산하는 다이나믹 프로그래밍(바텀업) 패턴이다. 공간을 O(1)로 최적화한 점이 특징이다.

📊 시간/공간 복잡도 분석

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

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

피드백: 두 단계의 합으로 현재의 경우의 수를 구하는 일반적인 DP 풀이입니다. 상수 공간으로 구현되어 효율적입니다.

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

풀이 2: Solution — 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,12 @@
class Solution:
# dynamic programming with bottom-up
# Time Complexity: O(n)
# Space Complexity: O(1)
def climbStairs(self, n: int) -> int:
if n <= 2: return n
prev1, prev2 = 2, 1

for i in range(3, n+1):
prev1, prev2 = prev2 + prev1, prev1

return prev1
7 changes: 7 additions & 0 deletions valid-anagram/njngwn.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, Greedy
  • 설명: 주어진 코드는 Counter를 이용해 각 문자의 등장 횟수를 비교하므로 해시 맵 기반의 패턴(Hash Map / Hash Set)을 활용합니다. 두 문자열의 다항 비교로 간단한 동등성 검사이므로 특수한 그리디는 해당하지 않지만, 해시 기반 카운트로 빈도 비교라는 점이 핵심입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from collections import Counter

class Solution:
# Time Complexity: O(n), n: max(len(s), len(t))
# Space Complexity: O(k), k: number of letters
def isAnagram(self, s: str, t: str) -> bool:
return Counter(s) == Counter(t)

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.

안녕하세요 이번주 리뷰를 맡게되었습니다 :)

Counter라는게 있군요? 엄청 깔끔하네요!
찾아보니 이게 문자열 돌면서 맵을 만들어주는 함수인 것 같네요.

그런데 len로 길이가 다른 경우 리턴하도록 체크를 먼저 해 주면, 불필요하게 맵을 만드는 비용을 줄일 수 있을 것 같아요.

Loading