方法一:(自己写的)
class Solution {
public int findMin(int[] nums) {
int i;
for(i=0;i<nums.length-1;i++) {
if(nums[i]>nums[i+1]) {
return nums[i+1];
}
}
return nums[0];
}
}
方法二:
二分思想
class Solution {
public int findMin(int[] nums) {
int low=0,high=nums.length-1;
while(low<high) {
int mid=low+(high-low)/2;
if(nums[mid]<nums[high]) {
high=mid;
}else {
low=mid+1;
}
}
return nums[low];
}
}