A way that's easy to understand


  • 0
    D
    int searchInsert(vector<int>& nums, int target) {
        for (int i=0;i<nums.size();i++){
            nums[i]=target-nums[i];
            if (nums[i]<=0) return i;
        }
        return nums.size();
    }

Log in to reply
 

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