[C] Intuitive Solution


  • 0
    H
    int* plusOne(int* digits, int digitsSize, int* returnSize) {
        int tail = digitsSize-1;
        digits[tail] += 1;
        *returnSize = digitsSize;
        while(tail > 0) {
            if(digits[tail] < 10) {
                return digits;
            }
            digits[tail] = 0;
            digits[tail-1] += 1;
            tail--;
        }
        if(digits[tail] < 10) return digits;
        *returnSize =  digitsSize+1;
        int*digits_more = calloc(*returnSize, sizeof(int));
        digits_more[0] = 1;
        
        return digits_more;
    }
    

Log in to reply
 

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