当前位置:网站首页>068. Find the insertion position -- binary search
068. Find the insertion position -- binary search
2022-07-06 09:34:00 【Prism 7】
List of articles
One 、code
1.1 Title Description
1.2 Answer key
class Solution {
// Two points search
public int searchInsert(int[] nums, int target) {
int left = 0;
int right = nums.length - 1;
if(nums[left] > target) return 0; // Left boundary
if(nums[right] < target) return nums.length; // Boundary
while(left <= right){
int mid = left + (right - left) / 2;
if(nums[mid] == target) return mid;
if(nums[mid] > target){
if(nums[mid - 1] < target){
return mid;
}
right = mid - 1;
}else{
left = mid + 1;
}
}
return 0;
}
}
Two 、 summary
边栏推荐
- O & M, let go of monitoring - let go of yourself
- go-redis之初始化連接
- Libuv thread
- Nacos installation and service registration
- [shell script] - archive file script
- LeetCode41——First Missing Positive——hashing in place & swap
- [deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction
- Kratos战神微服务框架(一)
- Redis geospatial
- What is an R-value reference and what is the difference between it and an l-value?
猜你喜欢
随机推荐
Global and Chinese markets for small seed seeders 2022-2028: Research Report on technology, participants, trends, market size and share
发生OOM了,你知道是什么原因吗,又该怎么解决呢?
【深度学习】语义分割:论文阅读:(2021-12)Mask2Former
MapReduce instance (V): secondary sorting
Basic usage of xargs command
Reids之删除策略
Advanced Computer Network Review(4)——Congestion Control of MPTCP
【深度学习】语义分割:论文阅读(NeurIPS 2021)MaskFormer: per-pixel classification is not all you need
MapReduce instance (IV): natural sorting
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本
Design and implementation of film and television creation forum based on b/s (attached: source code paper SQL file project deployment tutorial)
Master slave replication of redis
Five layer network architecture
Withdrawal of wechat applet (enterprise payment to change)
Full stack development of quartz distributed timed task scheduling cluster
[three storage methods of graph] just use adjacency matrix to go out
Global and Chinese markets for hardware based encryption 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market for annunciator panels 2022-2028: Research Report on technology, participants, trends, market size and share
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)