当前位置:网站首页>Leetcode- > binary search clock in
Leetcode- > binary search clock in
2022-07-27 02:51:00 【Half moon person】
class Solution {
public int search(int[] nums, int target) {
if(nums.length==1){
return nums[0]==target?0:-1;
}
int left = 0;
int right = nums.length-1;
while(left<=right){
int middle = (left+right)/2;
if(nums[middle]<target){
left = middle+1;
}else if(nums[middle]>target){
right = middle-1;
}else{
return middle;
}
}
return -1;
}
}class Solution {
public int search(int[] nums, int target) {
if(nums.length==1){
return nums[0]==target?0:-1;
}
int left = 0;
int right = nums.length-1;
while(left<=right){
int middle = (left+right)/2;
if(nums[middle]<target){
left = middle+1;
}else if(nums[middle]>target){
right = middle-1;
}else{
return middle;
}
}
return -1;
}
}边栏推荐
猜你喜欢

Make static routing accessible to the whole network through ENSP

从初级程序员到架构师学习路线+配套学习资源完整版

无效的目标发行版:17 的解决办法

Hcip the next day

白盒测试案例设计(我爷爷都能看懂)

If you want to thoroughly optimize the performance, you must first understand the underlying logic~

「软件测试」包装简历从这几点出发,直接提升通过率

【Redis】快速入门

Swiperjs custom width

Uni app wechat applet search keywords are displayed in red
随机推荐
函数栈帧详解
砺夏行动|源启数字化:既有模式,还是开源创新?
系统安全测试要怎么做,详细来说说
go语言慢速入门——go运算符
Function stack frame explanation
MySQL master-slave database configuration based on docker for Ubuntu
After working in Tencent testing post for 5 years, I was ruthlessly dismissed in July, trying to wake up my brother who was still paddling
银河证券基金低佣金开户靠谱吗,可靠安全吗
快速排序(Quick sort)
time模块: 时间戳、结构化时间、格式化时间的获取与相互转化
什么是进程?
【Code】剑指offer 04二维数组中的查找
手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
动态设置小程序swiper的高度
Hcip day 5 OSPF extended configuration experiment
[redis] five common data types
【Redis】快速入门
js utils 零碎
White box test case design (my grandfather can understand it)
Prometheus operation and maintenance tool promtool (III) debug function