Simple 0ms accepted solution


  • 0
    R
    int* plusOne(int* digits, int digitsSize, int* returnSize) {
    int* temp = (int*)malloc(sizeof(int)*(digitsSize + 1));
    memcpy(temp, digits, sizeof(int)*digitsSize);
    int n = digitsSize;
    while (n)
    {
    	if (digits[n - 1] < 9)
    	{
    		temp[n-1] = digits[n - 1] + 1;
    		break;
    	}
    	else
    	{
    		temp[n-1] = 0;
    	}
    	n--;
    }
    if (n == 0 && temp[0] == 0)
    {
    	temp[0] = 1;
    	temp[digitsSize] = 0;
    	*returnSize = digitsSize + 1;
    }
    else
    {
    	*returnSize = digitsSize;
    }
    
    return temp;
    

    }


Log in to reply
 

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