当前位置:网站首页>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
边栏推荐
- 基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
- 六月刷题02——字符串
- Leetcode problem solving 2.1.1
- IDS' deletion policy
- Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
- Kratos战神微服务框架(三)
- Kratos ares microservice framework (II)
- Global and Chinese markets of SERS substrates 2022-2028: Research Report on technology, participants, trends, market size and share
- Hard core! One configuration center for 8 classes!
- How to intercept the string correctly (for example, intercepting the stock in operation by applying the error information)
猜你喜欢

Nacos installation and service registration

Mapreduce实例(五):二次排序
![[shell script] - archive file script](/img/50/1bef6576902890dfd5771500414876.png)
[shell script] - archive file script

QDialog

Redis之Geospatial

Full stack development of quartz distributed timed task scheduling cluster

Le modèle sentinelle de redis

Activiti7工作流的使用

【深度学习】语义分割:论文阅读:(CVPR 2022) MPViT(CNN+Transformer):用于密集预测的多路径视觉Transformer

运维,放过监控-也放过自己吧
随机推荐
【每日一题】搬运工 (DFS / DP)
Segmentation sémantique de l'apprentissage profond - résumé du code source
Servlet learning diary 8 - servlet life cycle and thread safety
面渣逆袭:Redis连环五十二问,图文详解,这下面试稳了
英雄联盟轮播图手动轮播
Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
Redis之Bitmap
leetcode-14. Longest common prefix JS longitudinal scanning method
基于B/S的医院管理住院系统的研究与实现(附:源码 论文 sql文件)
[deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction
go-redis之初始化连接
英雄联盟轮播图自动轮播
Advanced Computer Network Review(4)——Congestion Control of MPTCP
Design and implementation of film and television creation forum based on b/s (attached: source code paper SQL file project deployment tutorial)
Detailed explanation of cookies and sessions
QML control type: menu
运维,放过监控-也放过自己吧
Global and Chinese markets for small seed seeders 2022-2028: Research Report on technology, participants, trends, market size and share
[Yu Yue education] Wuhan University of science and technology securities investment reference
[daily question] Porter (DFS / DP)