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 af39f1f commit 2267c00Copy full SHA for 2267c00
1 file changed
find-minimum-in-rotated-sorted-array/jylee2033.py
@@ -0,0 +1,21 @@
1
+class Solution:
2
+ def findMin(self, nums: List[int]) -> int:
3
+ # Binary Search: compare mid with right
4
+ # nums[mid] > nums[right] -> min is in right half
5
+ # nums[mid] < nums[right] -> min is in left half (including mid)
6
+
7
+ left = 0
8
+ right = len(nums) - 1
9
10
+ while left < right:
11
+ mid = (left + right) // 2
12
13
+ if nums[mid] > nums[right]:
14
+ left = mid + 1
15
+ elif nums[mid] < nums[right]:
16
+ right = mid
17
18
+ return nums[left]
19
20
+# Time Complexity: O(log n)
21
+# Space Complexity: O(1)
0 commit comments