当前位置:网站首页>Location of dichotomy
Location of dichotomy
2022-06-30 14:37:00 【Douglas_ LT】
A daily topic ing, Today is a day medium topic 34. Find First and Last Position of Element in Sorted Array
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
int l=0,r=nums.size()-1,mid=0;
while(l<=r){
mid=(l+r)/2;
if(target>=nums[mid]){
l=mid+1;
}
else if(target<nums[mid]){
r=mid-1;
}
}
vector<int> ret(2,-1);
if(r==-1||nums[r]!=target){
return ret;
}
int i=r;
while(i>=0&&nums[i]==target){
i--;
}
ret[0]=i+1;
int j=r;
while(j<=nums.size()-1&&nums[j]==target){
j++;
}
ret[1]=j-1;
return ret;
}
};
边栏推荐
- JS time conversion standard format, timestamp conversion standard format
- LIS error: this configuration section cannot be used in this path
- MV3 04_ Introducing Manifest V3
- Go language mutex lock
- PHP common authentication / third-party methods
- Knowledge learned from the water resources institute project
- How does hbuilder display in columns?
- Laravel upload error
- PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
- Summary of FTP network protocol learning
猜你喜欢

Notes on reverse learning in the first week of winter vacation
![[extensive reading of papers] multimodal attribute extraction](/img/ec/546c107ac0d31deded7ca94fdf0e2d.jpg)
[extensive reading of papers] multimodal attribute extraction

How to use Alibaba Vector Icon

XSS challenge (6-10) more detailed answers

Querywrapper in mybaits plus

Shangpinhui knowledge points of large e-commerce projects

KnightCTF WEB

Shell programming overview

Thinkphp5 log file contains trick

PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
随机推荐
2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
Laravel8 custom log directory, rename
go channel && select
Small exercise of process and signal
Implement a long-click list pop-up box on apiccloud
V3 03_ Getting started
@PathVariable
Clear the route cache in Vue
Solution cannot use a scalar value as an array
Judgment of deep learning experiment results
PS cutting height 1px, Y-axis tiling background image problem
【BUUCTF】[GXYCTF2019]Ping Ping Ping1
Problems in QT creator (additional unknown and error lines are listed in the debug output window)
KnightCTF WEB
@Component use cases
Use of laravel repository mode
remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac
Mutex lock, read / write lock, spin lock, pessimistic lock, and optimistic lock
Crypto questions
ctfshow nodejs