153. Find Minimum in Rotated Sorted Array

来源:互联网 发布:单机版笔记软件 编辑:程序博客网 时间:2024/06/03 18:20

Suppose an array sorted in ascending order 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.

Subscribe to see which companies asked this question.

public class Solution {    public int findMin(int[] nums) {        int left = 0;int right = nums.length - 1;while (left < right) {int mid = left + (right - left) / 2;if (nums[mid] > nums[right])left = mid+1;elseright = mid;}return nums[left];    }}


0 0
原创粉丝点击