当前位置:网站首页>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
边栏推荐
- [daily question] Porter (DFS / DP)
- Kratos战神微服务框架(三)
- 发生OOM了,你知道是什么原因吗,又该怎么解决呢?
- IDS' deletion policy
- 美团二面:为什么 Redis 会有哨兵?
- IDS cache preheating, avalanche, penetration
- Advanced Computer Network Review(4)——Congestion Control of MPTCP
- Basic usage of xargs command
- Redis之发布订阅
- Global and Chinese market of electronic tubes 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
Kratos战神微服务框架(一)
Redis之Lua脚本
[shell script] - archive file script
Mathematical modeling 2004b question (transmission problem)
DCDC power ripple test
基于B/S的影视创作论坛的设计与实现(附:源码 论文 sql文件 项目部署教程)
【深度学习】语义分割:论文阅读(NeurIPS 2021)MaskFormer: per-pixel classification is not all you need
Redis cluster
Oom happened. Do you know the reason and how to solve it?
Use of activiti7 workflow
随机推荐
Global and Chinese market of metallized flexible packaging 2022-2028: Research Report on technology, participants, trends, market size and share
Mapreduce实例(七):单表join
[three storage methods of graph] just use adjacency matrix to go out
数据建模有哪些模型
Redis geospatial
Heap (priority queue) topic
Global and Chinese markets for hardware based encryption 2022-2028: Research Report on technology, participants, trends, market size and share
Sentinel mode of redis
CSP student queue
xargs命令的基本用法
Redis之五大基础数据结构深入、应用场景
AcWing 2456. 记事本
Kratos ares microservice framework (I)
[Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology
Redis cluster
O & M, let go of monitoring - let go of yourself
[shell script] - archive file script
go-redis之初始化連接
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
QDialog