Medium
, Binary Search
Question
假設(shè)升序序列在某個(gè)點(diǎn)被旋轉(zhuǎn)了悦昵,尋找最小數(shù)惩嘉。
For Example
(0 1 2 4 5 6 7旋轉(zhuǎn)以后成為 4 5 6 7 0 1 2).
Notes
假設(shè)序列中無重復(fù)數(shù)字
Solution
使用二分搜索令漂。
class Solution(object):
def findMin(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
L, R = 0, len(nums)-1
while L<R and nums[L] > nums[R]:
M = (L+R)/2
if nums[M] > nums[R]:
L = M+1
else:
R = M
return nums[L]