Skip to content

[KwonNayeon] Week 4 solutions #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2025
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
16 changes: 6 additions & 10 deletions find-minimum-in-rotated-sorted-array/KwonNayeon.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""
Constraints:
- n == nums.length
- 1 <= n <= 5000
- -5000 <= nums[i] <= 5000
- All the integers of nums are unique.
- nums is sorted and rotated between 1 and n times.
Input/Output/Constraints:
- Input: A rotated sorted array (e.g., [4,5,6,7,0,1,2])
- Output: The minimum element in the array (e.g., 0)
- Constraints: Algorithm must run in O(log n) time

Time Complexity: O(log n)
- 이진 탐색을 사용하므로 매 단계마다 탐색 범위가 절반으로 줄어듦
Expand All @@ -16,19 +14,17 @@
1. 이진 탐색(Binary Search) 활용
2. mid와 right 값을 비교하여 조건을 나눔
- Case 1: nums[mid] > nums[right]
- 오른쪽 부분이 정렬되어 있지 않음
- 최솟값은 mid 오른쪽에 존재
- left = mid + 1
- Case 2: nums[mid] <= nums[right]
- mid부터 right까지는 정렬되어 있음
- 최솟값은 mid를 포함한 왼쪽에 존재 가능
- right = mid
3. Pivot이 일어난 지점의 값을 반환
"""

class Solution:
def findMin(self, nums: List[int]) -> int:
left = 0
right = len(nums) - 1
left, right = 0, len(nums) - 1

while left < right:
mid = (left + right) // 2
Expand Down
11 changes: 11 additions & 0 deletions merge-two-sorted-lists/KwonNayeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
2. -100 <= Node.val <= 100
3. list1 and list2 are sorted in non-decreasing order

<Solution 1>

Time Complexity: n과 m이 각각 list1과 list2의 길이를 나타낼 때, O(n + m)
- 각 노드를 한 번씩만 방문하기 때문

Expand Down Expand Up @@ -43,3 +45,12 @@ def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) ->
current.next = list2

return result.next

"""
<Solution 2>
Time Complexity:

Space Complexity:

풀이 방법:
"""