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
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 형태로 풀이되며, 반복문으로 상태를 축약하는 전형적인 DP 패턴입니다. 또한 최적해를 구하는 과정에서 중간 최적해를 이용하는 특성을 보입니다.

📊 시간/공간 복잡도 분석

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

피드백: 두 인접한 항의 합으로 다음 수를 계산하므로 시간은 선형이고 추가 공간은 상수입니다.

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

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

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
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
  • 설명: 배열의 모든 쌍을 비교하는 이중 루프 방식으로 중복 여부를 확인하는 전형적인 브루트 포스 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 중복 여부를 확인하는 가장 단순한 방식으로 시간복잡도가 제곱 증가합니다.

개선 제안: 집합을 사용하면 평균적으로 O(n) 시간으로 개선 가능하지만 현재 구조를 유지하는 경우도 있습니다.

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

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
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
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
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
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