A simple accepted solution


  • -2
    L
    int searchInsert(int A[], int n, int target) {
    int i;
    if(A[n-1]<target)
        return n;
    for(i=0;i<n;i++)
    {
        if(A[i]==target)
            return i;
        if(A[i]>target)
            return i;
    }
    }

Log in to reply
 

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