【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 might become 4 5 6 7 0 1 2).

Find the minimum element.

You may assume no duplicate exists in the array.

二、问题分析

变异的二分查找。

三、Java AC代码

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


你可能感兴趣的:(java,LeetCode,array,search,binary)