1 public class T008 { 2 public static void main(String[] args) { 3 int[] num = { 3, 4, 5, 1, 2 }; 4 System.out.println(min(num, 5)); 5 } 6 public static int min(int num[], int len) { 7 if (num == null || len <= 0) { 8 System.out.println("invalid"); 9 } 10 int in1 = 0; 11 int in2 = len - 1; 12 int inm = in1; 13 while (num[in1] >= num[in2]) { 14 if (in2 - in1 == 1) { 15 inm = in2; 16 break; 17 } 18 inm = (in2 + in1) / 2; 19 if (num[in1] == num[inm] && num[in1] == num[in2]) 20 return minInOrder(num, in1, in2); 21 if (num[inm] >= num[in1]) { 22 in1 = inm; 23 } else { 24 in2 = inm; 25 } 26 } 27 return num[inm]; 28 } 29 30 public static int minInOrder(int num[], int in1, int in2) { 31 int result = num[in1]; 32 for (int i = in1 + 1; i <= in2; i++) { 33 if (num[i] < result) 34 result = num[i]; 35 } 36 return result; 37 } 38 }
java实现——008旋转数组的最小数字,布布扣,bubuko.com
原文:http://www.cnblogs.com/thehappyyouth/p/3716263.html