Created
December 3, 2018 07:06
-
-
Save XcqRomance/f9b3c0ac95bb907aeda9a0f2ec3d20c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 6.加一 | |
int* plusOne(int* digits, int digitsSize, int* returnSize) { | |
if (digitsSize<=0) { | |
return digits; | |
} | |
int* ree =(int*)malloc((digitsSize)*sizeof(digits[0])); | |
for (int i = digitsSize-1; i >= 0; i--) { | |
if (digits[i] == 9) { | |
digits[i] = 0; | |
} else { | |
digits[i] += 1; | |
break; | |
} | |
} | |
if (digits[0] == 0) { | |
int j; | |
for(j=1;j<digitsSize+1;j++) ree[j]=0; | |
ree[0]=1; | |
* returnSize=digitsSize+1; | |
return ree; | |
} else { | |
* returnSize=digitsSize; | |
return digits; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment