当前位置:网站首页>leetcode 35. Search insert location
leetcode 35. Search insert location
2022-06-12 06:22:00 【Well, let me see】
35. Search insert location 
Thought analysis :
Dichotomous template question .
AC Code :
class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
if(nums.size() == 1) {
if(nums[0] < target) return 1;
else return 0;
}
int l = 0, r = nums.size() - 1;
while(l < r) {
int mid = (l + r) >> 1;
if(nums[mid] >= target) r = mid;
else l = mid + 1;
}
if(nums[r] < target)
return r + 1;
else
return r;
}
};
边栏推荐
猜你喜欢

How do I get the date and time from the Internet- How to get DateTime from the internet?

LeetCode个人题解(剑指offer3-5)3.数组中重复的数字,4.二维数组中的查找,5.替换空格

Bert use

Book classification based on Naive Bayes

Poisson disk sampling for procedural placement

Multithreading (4) -- no lock (3) -- longadder source code

AI作业ch8

Redis configuration (III) -- master-slave replication

Findasync and include LINQ statements - findasync and include LINQ statements

分段贝塞尔曲线
随机推荐
Unity custom translucent surface material shader
. Net core and Net framework comparison
English grammar_ Adverb_ With or without ly, the meaning is different
Video based fire smoke detection using robust AdaBoost
First note
The vs 2019 community version Microsoft account cannot be logged in and activated offline
dlib 人脸检测
GET 和 POST 的区别及留言板代码实现
JS pre parsing
How to increase heap size of JVM [duplicate] - how to increase heap size of JVM [duplicate]
Leetcode-1706. Where does the club fall
Sqlite Cross - compile Dynamic Library
Getting started with houdininengine HDA and UE4
On the normalization of camera rotation interpolation
PDF. js FAQs
Directx11 advanced tutorial tiled based deffered shading
Tips for using the potplayer video player
Leetcode-139. Word splitting
Cv2.fillpoly coco annotator segment coordinate conversion to mask image
Qt-- realize TCP communication