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]; 
    }
};
版权声明:转载表明出处

[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 6 7 ...

【leetcode】153. Find Minimum in Rotated Sorted Array

【leetcode】153. Find Minimum in Rotated Sorted Array

【leetcode】No.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 6 7 mig...

Find Minimum in Rotated Sorted Array - LeetCode 153

题目描述: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 ...
  • bu_min
  • bu_min
  • 2015年04月24日 21:50
  • 275

LeetCode - 153. Find Minimum in Rotated Sorted Array

O(n)和使用Arrays.sort(nums)的方法就不再写了。真是各种花式使用二分搜索啊...二分搜索的关键点在与left,right指针移动条件的判定,这道题目的判定条件非常巧妙。使用nums[...

LeetCode-153.Find Minimum in Rotated Sorted Array

https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Suppose a sorted array is rota...

[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 ...

153和154. Find Minimum in Rotated Sorted Array II

Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed? Would ...

【LeetCode-面试算法经典-Java实现】【153-Find Minimum in Rotated Sorted Array(找旋转数组中的最小数字)】

【153-Find Minimum in Rotated Sorted Array(找旋转数组中的最小数字)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Suppose...

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题目描述一个已经排好序的数...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:153 Find Minimum in Rotated Sorted Array
举报原因:
原因补充:

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