2024/9/14 LeetCode Hot100 binarySearch

This commit is contained in:
Cool 2024-09-15 01:33:06 +08:00
parent cbe6b62fa7
commit 396723a171
1 changed files with 30 additions and 0 deletions

View File

@ -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;
}
}