当前位置:网站首页>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
边栏推荐
- Segmentation sémantique de l'apprentissage profond - résumé du code source
- AcWing 2456. 记事本
- 【图的三大存储方式】只会用邻接矩阵就out了
- Go redis initialization connection
- 【每日一题】搬运工 (DFS / DP)
- The five basic data structures of redis are in-depth and application scenarios
- Detailed explanation of cookies and sessions
- 【shell脚本】——归档文件脚本
- LeetCode41——First Missing Positive——hashing in place & swap
- 五层网络体系结构
猜你喜欢
Advance Computer Network Review(1)——FatTree
解决小文件处过多
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)
【shell脚本】——归档文件脚本
发生OOM了,你知道是什么原因吗,又该怎么解决呢?
DCDC power ripple test
[Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology
Publish and subscribe to redis
Compilation of libwebsocket
Heap (priority queue) topic
随机推荐
[deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction
Mapreduce实例(十):ChainMapReduce
Seven layer network architecture
Global and Chinese market of metallized flexible packaging 2022-2028: Research Report on technology, participants, trends, market size and share
Parameterization of postman
IDS' deletion policy
QML type: overlay
Compilation of libwebsocket
【图的三大存储方式】只会用邻接矩阵就out了
Improved deep embedded clustering with local structure preservation (Idec)
Kratos ares microservice framework (III)
CAP理论
Redis之核心配置
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
软件负载均衡和硬件负载均衡的选择
Go redis initialization connection
Redis之连接redis服务命令
In depth analysis and encapsulation call of requests
【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本