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

LeetCode – Refresh – Find Minimum in Rotated Array II

时间:2015-03-19 10:07:57      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

lazy solutions..... Just skip the duplicates. Then worse case of time is O(n).

 

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

 

LeetCode – Refresh – Find Minimum in Rotated Array II

标签:

原文地址:http://www.cnblogs.com/shuashuashua/p/4349515.html

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