Skip to content

Instantly share code, notes, and snippets.

@XcqRomance
Created December 3, 2018 07:06
Show Gist options
  • Save XcqRomance/f9b3c0ac95bb907aeda9a0f2ec3d20c6 to your computer and use it in GitHub Desktop.
Save XcqRomance/f9b3c0ac95bb907aeda9a0f2ec3d20c6 to your computer and use it in GitHub Desktop.
// 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