Simple two line c++ solution

  • 0

    The idea is simple. With the lower_bound in STL can help us find the insertion position.

        int searchInsert(vector<int>& nums, int target) {
            vector<int>::iterator iter = lower_bound(nums.begin(),nums.end(),target);
            return iter - nums.begin();

Log in to reply

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