码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode------Find Minimum in Rotated Sorted Array II

时间:2015-02-15 12:07:22      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

标题: Find Minimum in Rotated Sorted Array II
通过率: 31.1%
难度:

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.

再第一版本中我已经详细介绍了旋转数组的特点。

Find Minimum in Rotated Sorted Array可以直接点击去看我对于旋转数组的分析。本题直接看代码

 1 public class Solution {
 2     public int findMin(int[] num) {
 3         int start=0,end=num.length-1,mid=0;
 4         while(start<end&&num[start]>=num[end]){
 5             mid=(start+end)/2;
 6             if(num[mid]>num[end])start=mid+1;
 7             else if(num[mid]<num[end])end=mid;
 8             else start+=1;
 9         }
10         return num[start];
11     }
12 }

 

leetcode------Find Minimum in Rotated Sorted Array II

标签:

原文地址:http://www.cnblogs.com/pkuYang/p/4292639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!