题目:
题解:
/*** Note: The returned array must be malloced, assume caller calls free().*/
int* plusOne(int* digits, int digitsSize, int* returnSize){for(int i = digitsSize - 1; i >= 0; --i){digits[i] = digits[i] + 1;//最后元素+1判断是不是10//如果当前元素不为10,直接返回数组if(digits[i] != 10){*returnSize = digitsSize;return digits;}//第一个元素不为10,后面元素均为10的情况if(digits[i] == 10)digits[i] = 0;}//元素全为9开辟新数组int* ans = malloc(sizeof(int) * (digitsSize + 1));memset(ans, 0, sizeof(int) * (digitsSize + 1));//全部置0ans[0] = 1;*returnSize = digitsSize + 1;return ans;
}