Skip to content

Commit 9b40844

Browse files
authored
Update 153._find_minimum_in_rotated_sorted_array.md
1 parent 703708a commit 9b40844

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/Leetcode_Solutions/Python/153._find_minimum_in_rotated_sorted_array.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,32 @@ class Solution(object):
5656
pivot = nums[i]
5757
return nums[0]
5858
```
59+
60+
61+
> 思路 2
62+
******- 时间复杂度: O(lgN)******- 空间复杂度: O(1)******
63+
64+
65+
二分法,思路看代码一目了然,[leetcode第33题](https://github.com/apachecn/awesome-algorithm/blob/master/docs/Leetcode_Solutions/Python/033._search_in_rotated_sorted_array.md)这道题很类似,我画了图的,可以看看
66+
67+
beats 100%
68+
69+
```python
70+
class Solution(object):
71+
def findMin(self, nums):
72+
"""
73+
:type nums: List[int]
74+
:rtype: int
75+
"""
76+
l, r = 0, len(nums) - 1
77+
while l <= r:
78+
mid = l + ((r-l) >> 1)
79+
if nums[mid] < nums[mid-1]:
80+
return nums[mid]
81+
elif nums[mid] < nums[l]:
82+
r = mid - 1
83+
elif nums[mid] > nums[r]:
84+
l = mid + 1
85+
else:
86+
return nums[l]
87+
```

0 commit comments

Comments
 (0)