sajid161

16:4

Apr 17th, 2021
465
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int searchInsert(vector<int>& nums, int target) {
  4.        
  5.         //int lo=lower_bound(nums.begin(),nums.end(),target)-nums.begin();
  6.        // return lo;
  7.         int l=0,r=nums.size()-1;
  8.         int res=-1;
  9.         while(l<=r)
  10.         {
  11.             int mid=(l+r)/2;
  12.             if(nums[mid]>=target)
  13.             {
  14.                res=mid;
  15.                 r=mid-1;
  16.             }
  17.             else l=mid+1;
  18.         }
  19.         if(res==-1) return nums.size();
  20.         else return res;
  21.     }
  22. };
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×