当前位置:网站首页>LeetCode->二分查找打卡
LeetCode->二分查找打卡
2022-07-26 23:17:00 【月半的人】
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;
}
}边栏推荐
- Wechat applet: user wechat login process (attached: flow chart + source code)
- Rip routing information protocol topology experiment
- 全连MGRE与星型拓扑MGRE
- Redis五种基本数据结构
- Plato Farm有望通过Elephant Swap,进一步向外拓展生态
- [draw rectangular coordinate system in C language]
- Hcip OSPF comprehensive experiment
- Use of golang - sync package (waitgroup, once, mutex, rwmutex, cond, pool, map)
- Record the star user of handsomeblog
- C语言 学生信息管理系统 基于数组 可以存取到文本文件
猜你喜欢

oSPF基础实验配置

Risc-v tool chain compilation notes

I was fired at the age of 30. I want to understand a few things

C language - first program, print, variables and constants
![[draw sherpinski triangle in C language]](/img/e6/9d1d088d1c7675c23725443000329b.png)
[draw sherpinski triangle in C language]

Find a specific number in an ordered array

动态路由配置

Graduated and entered HW, from test engineer to project manager. Now I earn millions in goose factory every year. My suggestions to you

Handsomeforum Learning Forum

Redis五种基本数据结构
随机推荐
Interesting C language
excel整行删除,图片一起删除
Towhee 每周模型
毕业进入HW,从测试工程师到项目经理,现如今在鹅厂年收入百万,我的给大家的一些建议...
Find a specific number in an ordered array
动态路由配置
Detailed source code of golang bufio reader
Hcip the next day
The XML format of labelimg annotation is converted to yolov5
Talk about the metrics of automated testing
How to judge whether a number is odd or even?
祝大家七夕快乐,邀你源码共读
关于序列化变量保存的坑,加了索引器的数据不能序列化
OSPF路由信息协议-拓扑实验
JS 数组去重(含简单数组去重、对象数组去重)
【自此文之后,学习链表一片坦途】
Summary of dataset operations in ppocrlabel format.
Hcip first day
【你了解Cache吗——全面理解高速缓冲存储器】
【洋哥带你玩转线性表(三)——双向链表】