当前位置:网站首页>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之Bitmap
- 一文读懂,DDD落地数据库设计实战
- What is MySQL? What is the learning path of MySQL
- Redis之持久化实操(Linux版)
- 【深度学习】语义分割:论文阅读:(2021-12)Mask2Former
- Full stack development of quartz distributed timed task scheduling cluster
- In order to get an offer, "I believe that hard work will make great achievements
- 英雄联盟轮播图自动轮播
- 【图的三大存储方式】只会用邻接矩阵就out了
- CAP理论
猜你喜欢

IDS' deletion policy

Nacos installation and service registration

面渣逆袭:Redis连环五十二问,图文详解,这下面试稳了

Servlet learning diary 8 - servlet life cycle and thread safety

An article takes you to understand the working principle of selenium in detail

Compilation of libwebsocket

MapReduce instance (VI): inverted index

Redis cluster

基于B/S的影视创作论坛的设计与实现(附:源码 论文 sql文件 项目部署教程)

MapReduce instance (V): secondary sorting
随机推荐
Redis geospatial
Global and Chinese market of AVR series microcontrollers 2022-2028: Research Report on technology, participants, trends, market size and share
Servlet learning diary 8 - servlet life cycle and thread safety
为拿 Offer,“闭关修炼,相信努力必成大器
Connexion d'initialisation pour go redis
Webrtc blog reference:
运维,放过监控-也放过自己吧
一文读懂,DDD落地数据库设计实战
Kratos ares microservice framework (I)
七层网络体系结构
Lua script of redis
【深度学习】语义分割:论文阅读:(2021-12)Mask2Former
Sentinel mode of redis
Leetcode problem solving 2.1.1
Redis cluster
[deep learning] semantic segmentation - source code summary
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
QML control type: Popup
018.有效的回文
五月集训总结——来自阿光