easy c++ clean code / log(n)


  • 0
     int searchInsert(vector<int>& nums, int target) 
    { 
     int l=0,r=nums.size()-1;
        if(target>nums[r])return r+1;
        int mid=0;
        while(l<r-1)
        {
            mid=(l+r)>>1;
            if(nums[mid]>=target)
                r=mid;
            else 
                l=mid+1;    //l will be impossible. 
        }
        return l;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.