Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
21 changes: 21 additions & 0 deletions climbing-stairs/chapse57.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, Greedy
  • 설명: 클래식 피보나치 수열 기반의 DP 형태로, 이전 두 값을 이용해 현재 값을 계산하며 최적해를 구한다.

📊 시간/공간 복잡도 분석

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

피드백: 입력 n에 대해 상수 공간으로 마지막 두 값을 유지하며 반복으로 결과를 구한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""


if n == 1:
return 1
if n == 2:
return 2
a = 1
b = 2

for i in range(n - 2):
c = a + b
a = b
b = c
Comment on lines +17 to +19

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.

공간복잡도 고려한 점은 좋습니다. 다만 변수명을 좀 더 구체적으로 작성해주시면 리뷰어 입장에서 검토하기 좋으니 고려해주시면 좋을 것 같습니다.

return c

11 changes: 11 additions & 0 deletions contains-duplicate/chapse57.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Brute Force
  • 설명: 두 원소를 이중 순회하여 동일한 값이 있는지 확인하는 방법으로, 가장 단순한 탐색 패턴인 Brute Force에 해당합니다. 시간 복잡도 O(n^2)으로 비효율적이지만 구현이 간단합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n^2)
Space O(1)

피드백: 중첩 루프를 통해 모든 쌍을 비교하므로 시간 복잡도가 n^2이다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if nums[i] == nums[j]:
return True
return False
17 changes: 17 additions & 0 deletions group-anagrams/chapse57.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, Sorting
  • 설명: 문자열을 정렬한 키를 해시 맵에 매핑해 같은 아나그램을 묶는 방식으로 중복 여부를 해시 맵으로 관리한다. 정렬은 변환 키 생성, 해시 맵은 그룹으로 묶는 역할을 한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n * m log m)
Space O(n * m)

피드백: 각 단어별로 정렬 cost가 존재하고 해시맵에 그룹을 저장한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
seen = {}
for word in strs:
key = "".join(sorted(word))
# key가 seen에 이미 있으면 → word 추가
# 없으면 → 새로 만들기
if key in seen:
seen[key].append(word)
else:
seen[key] = [word]
return list(seen.values())

22 changes: 22 additions & 0 deletions top-k-frequent-elements/chapse57.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, Sorting
  • 설명: 입력 수를 해시 맵으로 세고, 각 원소의 빈도수를 기준으로 정렬하여 상위 k개를 뽑는 방식으로 구성되어 있습니다. 해시 맵을 사용한 카운트와 빈도 기반 정렬이 핵심 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 빈도 수를 내림차순으로 정렬하는 비용이 주된 시간 복잡도다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution(object):
def topKFrequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
count = {}
for n in nums:
if n in count:
count[n] +=1
else:
count[n] =1
# count.items()를 횟수 큰 순으로 정렬
freq = sorted(count.items(), key=lambda x: x[1], reverse=True)

result = []
for x in freq[:k]:
result.append(x[0])
return result


14 changes: 14 additions & 0 deletions two-sum/chapse57.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
  • 설명: 해당 코드는 해시 맵으로 값을 저장하고, 타깃-현재값의 존재 여부를 확인하여 한 번의 순회로 답을 찾는 방식이다. 두 포인터가 아니라 해시 맵 기반의 탐색으로 특정 패턴을 적용한다.

📊 시간/공간 복잡도 분석

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

피드백: 최적의 선형 시간 솔루션으로 일반적인 접근이다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
seen = {}
for i in range(len(nums)):
if (target - nums[i]) in seen:
return [seen[target - nums[i]],i]
seen[nums[i]] =i


11 changes: 11 additions & 0 deletions valid-anagram/chapse57.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sorting
  • 설명: 두 문자열을 정렬한 뒤 비교하는 방식으로 동일 여부를 판단하므로 정렬 기반 비교 패턴에 속합니다. 일반적으로 입력 크기에 따라 시간 복잡도 O(n log n)가 특징입니다.

📊 시간/공간 복잡도 분석

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

피드백: 정렬 비용이 주된 시간 복잡도이며 추가 공간은 정렬 방식에 따라 달라진다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
return sorted(s) == sorted(t)



Loading