Skip to content

Commit 54b9019

Browse files
committed
docs: add time and space complexity
1 parent 80ad178 commit 54b9019

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

contains-duplicate/hyogshin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ def containsDuplicate(self, nums: List[int]) -> bool:
44
return False
55
else:
66
return True
7-
7+
8+
9+
10+
'''
11+
시간 복잡도: O(n)??
12+
공간 복잡도: set을 활용해 nums 리스트를 복사함 -> len(nums)의 2배?
13+
'''

house-robber/hyogshin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ def rob(self, nums: List[int]) -> int:
99
dp[i] = max(dp[i-2] + nums[i], dp[i-1])
1010

1111
return max(dp)
12-
12+
13+
'''
14+
시간 복잡도: for loop -> O(n)
15+
공간 복잡도: dp 배열
16+
'''

longest-consecutive-sequence/hyogshin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ def longestConsecutive(self, nums: List[int]) -> int:
1616

1717
rs.append(cnt)
1818
return max(rs)
19-
19+
20+
'''
21+
시간 복잡도: for loop 1회 -> O(n)
22+
공간 복잡도: nums 리스트 + rs 배열 (최대 len(nums)) + sorted로 nums 배열 복사
23+
'''

top-k-frequent-elements/hyogshin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
2121
minus[idx] = 0
2222

2323
return ans
24-
24+
25+
'''
26+
시간 복잡도: for loop 2회 -> O(2n) -> O(n)
27+
공간 복잡도: 배열 크기 (10**4 + 1) 두 개 + nums 리스트 + ans 배열
28+
'''

two-sum/hyogshin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
1111
rs.append(idx)
1212
break
1313
return rs
14-
14+
15+
'''
16+
시간 복잡도: for loop 사용 -> O(n)
17+
공간 복잡도: len(nums) + rs 배열에서 number 2개 저장
18+
'''

0 commit comments

Comments
 (0)