0ms solution...


  • 0
    B

    0ms

    int* plusOne(int* digits, int digitsSize, int* returnSize) {
        int c = 0;
        digits[digitsSize - 1]++;
        for (int i = digitsSize - 1 ;i >= 0;i--){
            digits[i] += c;
            if (digits[i] >= 10){
                c = 1;
                digits[i] %= 10;
            }else{
                c = 0;
            }
        }
        int *tmp;
        if (c){
            *returnSize = digitsSize + 1;
            tmp = malloc(sizeof(int) * (*returnSize));
            tmp[0] = 1;
            for (int i = 0;i < digitsSize;i++)
                tmp[i + 1] = digits[i];
        }else{
            *returnSize = digitsSize;
            tmp = malloc(sizeof(int) * (*returnSize));
            for (int i = 0;i < digitsSize;i++)
                tmp[i] = digits[i];
        }
        return tmp;
    }
    

Log in to reply
 

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