当前位置:网站首页>35. search insertion position
35. search insertion position
2022-06-11 05:17:00 【qq_ twenty-six million three hundred and ninety-one thousand tw】
/* * Given a sort array and a target value , Find the target value in the array , And return its index . If the target value does not exist in the array , Return to where it will be inserted in sequence . * */
/** * @param {number[]} nums * @param {number} target * @return {number} */
var searchInsert = function(nums, target) {
if(!nums||!nums.length){
return 0;
}
var l=0,r=nums.length-1,mid=0;
while (l<r){
mid=parseInt((l+r)/2);
if(nums[mid]===target){
return mid;
}else if(nums[mid]<target){
l=mid+1;
}else {
r=mid;// If change to r=mid-1, sign out while when , There may be l>r,target Need and nums[l],nums[r] Compare them
}
}
l=nums[l]<target?l+1:l
// Calculation :nums:[1,3,5,6],target=7 when , Added , sign out while when ,l=r,
// So at this time ,nums[l]><=target It's possible , When nums[l]>=target when , Should return to l, Otherwise, we should return to l+1
return l;
};
边栏推荐
- NVIDIA SMI has failed because it could't communicate with the NVIDIA driver
- Combien de courant le câblage des PCB peut - il supporter?
- 自定义View基础之Layout
- Share 𞓜 jointly pre training transformers on unpaired images and text
- Zed2 camera calibration -- binocular, IMU, joint calibration
- Click the icon is not sensitive how to adjust?
- 华为设备配置本地虚拟专用网互访
- Using keras to build the basic model yingtailing flower
- oh my zsh正确安装姿势
- Thesis 𞓜 jointly pre training transformers on unpaired images and text
猜你喜欢

IOU series (IOU, giou, Diou, CIO)

Huawei equipment is configured to access the virtual private network through GRE tunnel

Share | guide language image pre training to achieve unified visual language understanding and generation

NVIDIA SMI has failed because it could't communicate with the NVIDIA driver

New product pre-sale: 25g optical network card based on Intel 800 series is coming

Oh my Zsh correct installation posture

Paper recommendation: relicv2, can the new self supervised learning surpass supervised learning on RESNET?
![[aaai 2021 timing action nomination generation] detailed interpretation of bsn++ long article](/img/28/d69a7583036a2076facffcf9098d7e.jpg)
[aaai 2021 timing action nomination generation] detailed interpretation of bsn++ long article

Apply the intelligent OCR identification technology of Shenzhen Yanchang technology to break through the bottleneck of medical bill identification at one stroke. Efficient claim settlement is not a dr

Introduction to coordinate system in navigation system
随机推荐
Paper recommendation: relicv2, can the new self supervised learning surpass supervised learning on RESNET?
Using keras to build the basic model yingtailing flower
Section II: structural composition characteristics of asphalt pavement (1) structural composition
Common methods of tool class objectutil
Leetcode 161 Editing distance of 1 (2022.06.10)
自定义View基础之Layout
一大厂95后程序员对部门领导不满,删库跑路被判刑
mysql字符串转数组,合并结果集,转成数组
华为设备配置跨域虚拟专用网
How to apply for free idea with official documents
Poverty has nothing to do with suffering
lower_ Personal understanding of bound function
Opencv learning path (2-2) -- Deep parsing namedwindow function
Detailed explanation of network security bypass network card
华为设备配置BGP/MPLS IP 虚拟专用网命令
Combien de courant le câblage des PCB peut - il supporter?
Following the wave of lack of core, Lianrui launched a number of gigabit network card solutions
推荐一款免费的内网穿透开源软件,可以在测试本地开发微信公众号使用
Comparison of gigabit network card chips: who is better, a rising star or a Jianghu elder?
go MPG