35. Search Insert Position

 class Solution {

public:

    int searchInsert(vector<int>& nums, int target) {

    int s=0,e=nums.size()-1;

    while(s<e){

        int  mid=s + (e-s)/2;

        if(nums[mid]>=target)

            e=mid;

        else

            s=mid+1;

    }

    return nums[s]>=target?s:s+1;

}

};

Comments

Popular posts from this blog

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones