一行代码搞定!
import java.util.*; public class Solution { public int minNumberInRotateArray(int [] array) { return Arrays.stream(array).min().getAsInt(); } }上面那个时间和空间都快逼近爆了哈哈,作死的边缘反复横跳,还是二分才是正解!
import java.util.*; public class Solution { public int minNumberInRotateArray(int [] array) { int left = 0,mid = 0; int right = array.length - 1; while(left < right){ mid = (left + right) / 2; if(array[mid] > array[right]) left = mid + 1; else if(array[mid] < array[right]) right = mid; else right--; } return array[left]; } }