 # [米群网刷题小分队] 【Find Minimum in Rotated Sorted Array】（Dec,7）每天两道，python解答参考

20主题 586积分 586 发表于 12-7-2014 12:03 PM | 显示全部楼层 |阅读模式

### 亲！马上注册或者登录会查看更多内容！

x

Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

Find the minimum element.
You may assume no duplicate exists in the array.

Follow up for "Find Minimum in Rotated Sorted Array":
What if duplicates are allowed?
Would this affect the run-time complexity? How and why?

Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

Find the minimum element.
The array may contain duplicates.  python参考解答：

[code]class Solution:
# @param num, a list of integer
# @return an integer
def findMin(self, num):
L = 0; R = len(num)-1
while L < R and num[L] > num[R]:
M = (L+R)/2
if num[M] < num[R]:
R = M
else:
L = M+1
return num[L][/code]

[code]class Solution:
# @param num, a list of integer
# @return an integer
def findMin(self, num):
L = 0; R = len(num)-1
while L < R and num[L] >= num[R]:
M = (L+R)/2
if num[M] > num[L]:
L = M + 1
elif num[M] < num[R]:
R = M
else:
L += 1
return num[L][/code]

### 本帖被以下淘专辑推荐:

18主题 522积分 522 发表于 12-7-2014 12:11 PM | 显示全部楼层
 顶一下，很少看见python的解法
 本版积分规则 回帖后跳转到最后一页   