C solution


  • 0
    X

    The point is, if we if we didn't found the position, there will be a 'n = numsSize'.

    int searchInsert(int* nums, int numsSize, int target) {
        int i;
        int n = numsSize;
        for(i = 0 ; i < numsSize; i ++)
        {
            if(nums[i] >= target)
            {
                n = i; 
                break;
            }
        }
        return n;
    }
    

Log in to reply
 

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