友情提示: 代码在这里
本文参照该仓库学习,大家可以star
二分查找
原理
1. 正常实现
public class binarySearch {
public int BinarySearch(int[] nums,int key){
int l = 0,h = nums.length-1;
while(l<=h)
{
int m = (l+h)/2;
if(nums[m] == key)
{
return m;
} else if(nums[m]<key)
{
l = m+1;
}else {
h = m-1;
}
}
return -1;
}
}
标签:二分,思想,nums,int,public,binarySearch,Leetcode
From: https://www.cnblogs.com/tuzichun/p/17079095.html