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 lo=lower_bound(nums.begin(),nums.end(),target)-nums.begin();
- // return lo;
- int l=0,r=nums.size()-1;
- int res=-1;
- while(l<=r)
- {
- int mid=(l+r)/2;
- if(nums[mid]>=target)
- {
- res=mid;
- r=mid-1;
- }
- else l=mid+1;
- }
- if(res==-1) return nums.size();
- else return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement