当前位置:网站首页>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
边栏推荐
猜你喜欢
Redis之核心配置
Mapreduce实例(六):倒排索引
Advanced Computer Network Review(3)——BBR
Nacos installation and service registration
Activiti7工作流的使用
[deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction
【深度學習】語義分割-源代碼匯總
Improved deep embedded clustering with local structure preservation (Idec)
【深度学习】语义分割:论文阅读:(CVPR 2022) MPViT(CNN+Transformer):用于密集预测的多路径视觉Transformer
五月集训总结——来自阿光
随机推荐
Redis之核心配置
Workflow - activiti7 environment setup
Kratos ares microservice framework (III)
为什么要数据分层
Global and Chinese markets for modular storage area network (SAN) solutions 2022-2028: Research Report on technology, participants, trends, market size and share
IDS cache preheating, avalanche, penetration
解决小文件处过多
In depth analysis and encapsulation call of requests
Advance Computer Network Review(1)——FatTree
The carousel component of ant design calls prev and next methods in TS (typescript) environment
[deep learning] semantic segmentation: paper reading: (2021-12) mask2former
Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
Mathematical modeling 2004b question (transmission problem)
Full stack development of quartz distributed timed task scheduling cluster
英雄联盟轮播图自动轮播
工作流—activiti7环境搭建
QML type: overlay
Design and implementation of film and television creation forum based on b/s (attached: source code paper SQL file project deployment tutorial)
MapReduce instance (VI): inverted index
Kratos战神微服务框架(一)