当前位置:网站首页>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
边栏推荐
- Compilation of libwebsocket
- 为拿 Offer,“闭关修炼,相信努力必成大器
- Global and Chinese market of electronic tubes 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of SERS substrates 2022-2028: Research Report on technology, participants, trends, market size and share
- Scoped in webrtc_ refptr
- MapReduce instance (IV): natural sorting
- Withdrawal of wechat applet (enterprise payment to change)
- CSP salary calculation
- Redis geospatial
- DCDC power ripple test
猜你喜欢

Opencv+dlib realizes "matching" glasses for Mona Lisa

运维,放过监控-也放过自己吧

LeetCode41——First Missing Positive——hashing in place & swap

Redis core configuration

Redis之持久化实操(Linux版)

Once you change the test steps, write all the code. Why not try yaml to realize data-driven?

Sentinel mode of redis

Redis之发布订阅

Improved deep embedded clustering with local structure preservation (Idec)

【深度學習】語義分割-源代碼匯總
随机推荐
小白带你重游Spark生态圈!
Redis cluster
为什么要数据分层
Mapreduce实例(九):Reduce端join
解决小文件处过多
Redis之持久化实操(Linux版)
Heap (priority queue) topic
Reids之缓存预热、雪崩、穿透
Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
[deep learning] semantic segmentation: paper reading: (2021-12) mask2former
基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)
Kratos战神微服务框架(二)
Improved deep embedded clustering with local structure preservation (Idec)
Mathematical modeling 2004b question (transmission problem)
六月刷题01——数组
Full stack development of quartz distributed timed task scheduling cluster
Mapreduce实例(六):倒排索引
Global and Chinese market of cup masks 2022-2028: Research Report on technology, participants, trends, market size and share
五层网络体系结构