2024/9/14 LeetCode Hot100 binarySearch
This commit is contained in:
parent
cbe6b62fa7
commit
396723a171
|
@ -0,0 +1,30 @@
|
|||
package com.cool.hot100.binary_search;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/09/15/1:32
|
||||
* DayNumber 2
|
||||
* Hard 2
|
||||
* Level 5
|
||||
*/
|
||||
public class Num153 {
|
||||
|
||||
public int findMin(int[] nums) {
|
||||
int left=0;
|
||||
int right=nums.length-1;
|
||||
int min=Integer.min(nums[0],nums[nums.length-1]);
|
||||
while(left<=right){
|
||||
int mid=left+(right-left)/2;
|
||||
if(nums[mid]>=nums[0]){
|
||||
left=mid+1;
|
||||
}else{
|
||||
right=mid-1;
|
||||
}
|
||||
min=Integer.min(min,nums[mid]);
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue