We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cffba1a commit b22c9eaCopy full SHA for b22c9ea
find-minimum-in-rotated-sorted-array/mangodm-web.py
@@ -0,0 +1,24 @@
1
+from typing import List
2
+
3
4
+class Solution:
5
+ def findMin(self, nums: List[int]) -> int:
6
+ """
7
+ - Idea: 회전된 정렬 배열에서 가장 작은 값을 찾기 위해 두 개의 포인터, left, right를 이용한다.
8
+ 두 개의 포인터는 조건에 따라 배열에서 탐색할 범위를 줄여가는데 활용된다.
9
+ - Time Complexity: O(logn). n은 배열의 크기이다.
10
+ 매번 배열을 절반으로 나눠서 탐색 범위를 줄이기 때문에 O(logn) 시간이 걸린다.
11
+ - Space Complexity: O(1). 배열의 크기와 상관없이 left, right, mid 변수만 사용되므로
12
+ 상수 공간만 차지한다.
13
14
+ left, right = 0, len(nums) - 1
15
16
+ while left < right:
17
+ mid = (left + right) // 2
18
19
+ if nums[right] < nums[mid]:
20
+ left = mid + 1
21
+ else:
22
+ right = mid
23
24
+ return nums[left]
0 commit comments