package leetcode; public class offer_11 { public int minArray(int[] numbers) { int left=0; int right=numbers.length-1; int mid=0; while(left<right) { mid=(left+right)/2; //numbers[mid]>numbers[right],则值只可能在mid与right之间 if(numbers[mid]>numbers[right]) { left=mid+1; //numbers[mid]<numbers[right],则值只可能在mid与left之间 }if(numbers[mid]<numbers[right]) { right=mid; //无法判断最小值在哪个半区 }else if (numbers[mid]==numbers[right]) { right=right-1; } } return numbers[left]; } public static void main(String[] args) { // TODO Auto-generated method stub offer_11 off=new offer_11(); int[] numbers= {3,1,3}; System.out.println(off.minArray(numbers)); } }
本文摘自 :https://www.cnblogs.com/