My 5 line C++ solution(doesnt involve binary search)


  • 0
    B

    class Solution {
    public:
    int searchInsert(vector<int>& nums, int target) {
    int i;
    for(i=0;i<nums.size();i++)
    {
    if(nums[i]>=target)
    return i;
    }
    return i;
    }
    };


Log in to reply
 

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