Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int searchInsert(vector<int>& nums, int target) {
- int n = nums.size();
- int l = 0;
- int h = n-1;
- //To find the first true for the condition nums[m]>=target
- while(l<h){
- int m = l + (h-l)/2;
- if(nums[m]>= target){
- h = m;
- }
- else{
- l = m+1;
- }
- }
- if(target>nums[n-1])return n;
- return l;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement