Skip to content
Merged
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
33 changes: 33 additions & 0 deletions merge-intervals/jamiebase.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
  • 설명: 이 코드는 정렬된 배열에서 두 포인터를 이용해 겹치는 구간을 병합하는 방식으로, 두 포인터 패턴을 활용한 대표적인 예입니다.

📊 시간/공간 복잡도 분석

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

피드백: 배열 정렬 후 한 번 순회하며 병합하는 방식으로, 정렬이 시간 복잡도를 지배합니다. 병합 과정은 선형입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
# Approach
1. 현재 범위 & 비교 범위 변수
2. 비교 범위의 start가 현재 범위의 end보다 같거나 작으면 merge 가능
3. 최종 merge 범위를 현재 범위로 재갱신 & output 배열에 추가하는 방식

# Complexity
- Time complexity: intervals의 길이를 N, 정렬 때문에 O(N log N)
- Space complexity: output 배열이 최악의 경우 O(N)
"""


class Solution:
def merge(self, intervals: list[list[int]]) -> list[list[int]]:
if (n := len(intervals)) == 1:
return intervals

intervals.sort(key=lambda x: x[0])
output = []
right = 1
start, end = intervals[0]

while right < n:
comp_start, comp_end = intervals[right]
if comp_start <= end:
end = max(comp_end, end)
else:
output.append([start, end])
start, end = comp_start, comp_end
right += 1

output.append([start, end])
return output
17 changes: 17 additions & 0 deletions missing-number/jamiebase.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
  • 설명: 이 코드는 집합을 이용해 존재 여부를 빠르게 확인하는 방식으로, 해시 맵 또는 해시 세트 패턴에 속합니다. 이를 통해 시간 복잡도를 낮추고 효율적으로 없는 숫자를 찾습니다.

📊 시간/공간 복잡도 분석

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

피드백: 집합을 통해 존재 여부를 빠르게 검사하며, 전체 배열을 한 번 순회합니다. 공간은 집합 크기만큼 필요합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
# Approach
nums 집합을 만들어 없는 숫자를 찾습니다.

# Complexity
- Time complexity: nums 의 길이를 n이라고 할 때, O(n)
- Space complexity: O(n)
"""


class Solution:
def missingNumber(self, nums: list[int]) -> int:
nums_set = set(nums)
n = len(nums)
for i in range(0, n + 1):
if i not in nums_set:
return i
Loading