Leetcode 153. Find Minimum in Rotated Sorted Array

来源:互联网 发布:cpu散片淘宝店家推荐? 编辑:程序博客网 时间:2024/06/07 16:39
/** * binary search approach, o(logN) */ public class Solution {    public int findMin(int[] nums) {        int low = 0, high = nums.length-1, mid;        while (low < high) {            mid = (low+high)/2;            // the smallest must be in the right side            // and nums[mid] cannot be the smallest, thus let low = mid+1 (*)            if (nums[mid] > nums[high])                low = mid+1;            // the smallest must be in the left side            // nums[mid] could be the samllest, thus let high = mid (*)            else                high = mid;        }        return nums[low];    }}

0 0