Here is my solution in C ( 0 ms)


  • 0
    S
    int* plusOne(int* a, int n, int* n2) 
    {
        int i,j,k=1;
        int*a2=(int*)malloc(sizeof(int)*(n+1));
        for(i=n-1;i>=0;i--)
        {
            j=(a[i]+k)%10;
            a2[i+1]=j;
            k=(a[i]+k)/10;
        }
        
        if(a2[1]==0)
        {   *n2=n+1;
            a2[0]=1;
            return a2;
        }
        else
        {   
            *n2=n; 
            return a2+1;
        } 
        
    }

  • 0
    C

    Nice and easy to follow solution~


Log in to reply
 

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