【第22期】观点:IT 行业加班,到底有没有价值?

153 Find Minimum in Rotated Sorted Array

原创 2015年07月07日 11:15:21

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.

class Solution {
public:
    int findMin(vector<int>& nums) {
        int len = nums.size();  
        if (len == 1) return nums[0];  
        int left = 0, right = len-1;  
        while (nums[left] > nums[right]) { 
            int mid = (left + right) / 2;  
            if (nums[mid] > nums[right]) {  
                left = mid + 1;  
            } else {  
                right = mid; 
            }  
        }  
        return nums[left]; 
    }
};
版权声明:转载表明出处 举报

相关文章推荐

153. Find Minimum in Rotated Sorted Array\229. Majority Element II\Moore's voting algorithm

Find Minimum in Rotated Sorted Array 题目描述 代码实现153. Find Minimum in Rotated Sorted Array题目描述一个已经排好序的数...

[LeetCode]154.Find Minimum in Rotated Sorted Array II

【题目】 <blockquote style="padding: 10px 20px; margin: 0px 0px 20px; font-size: 17.5px; border-left-width: 5px; border-left-style: solid; bord...

程序员升职加薪指南!还缺一个“证”!

CSDN出品,立即查看!

[LeetCode]153.Find Minimum in Rotated Sorted Array

【题目】 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 ...

[LeetCode]153.Find Minimum in Rotated Sorted Array

【题目】 Suppose a sorted array is rotated at some pivot unknown to you beforehan

Leetcode 153. Find Minimum in Rotated Sorted Array (Medium) (cpp)

Leetcode 153. Find Minimum in Rotated Sorted Array (Medium) (cpp)
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)