C++ O(N) solution


  • 0
    A
    class Solution {
    public:
        int searchInsert(vector<int>& nums, int target) 
        {
            unsigned int i = 0;
            unsigned int n = nums.size();
            
            while(i < n && nums[i] < target)
            {
                i++;
            }
            
            return i;
        }
    };
    

Log in to reply
 

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