LeetCode066 + 1 C语言

   Given  a  non-negative  number  represented  as  an  array  of 数字,plus  one 用,号码。   从而digits 断开连接;stored  such  that 从而most  significant  digit  is  at 从而head  of 从而列表。

题意:一个非负的整数用数组的形式保存着。其中高位在[0]。然后对这个数做加1操作,返回这个数组。

PS:原谅我又么有读懂题意——!

/* *   ,* Return  an  array  of  size  * returnSize。   ,*注意:,,returned  array  must  be  malloc,, assume  caller  calls 自由()。   ,*/int *, plusOne (int *,数字,int  digitsSize,, int *, returnSize), {   ,,,int 我;   ,,,int 指数=0;   ,,,int 携带=0;   ,,,int 标志=1;   ,,,//感觉是偷了个懒,只有全是9的时候才进1,所以   ,,,//只有个位数加1,不是每个都加,所以用国旗   ,,,(i=digitsSize-1; i>=0;我——){   ,,,,,,,//不是每个都加1   ,,,,,,,如果(数字[我]+国旗+ index> 9) {   ,,,,,,,,,,,数字[我]=0;   ,,,,,,,,,,,指数=1;   ,,,,,,,,,,,如果(我==0){   ,,,,,,,,,,,,,,,携带=1;   ,,,,,,,,,,,}   ,,,,,,,其他}{   ,,,,,,,,,,,数字[我]=数字[我]+ 1;   ,,,,,,,,,,,休息;   ,,,,,,,}   ,,,,,,,国旗=0;   ,,,,,,,//,printf (" % d”,数字[我]);   ,,,},,,,   ,,,//这个值也得写明白,不然程序不知道吗? ? ?   ,,,* returnSize=digitsSize +携带;      ,,,如果(携带){   ,,,,,,,int  * newdigits=(int *) malloc (sizeof (int) * digitsSize + 1);   ,,,,,,,newdigits [0]=1;   ,,,,,,,,(i=1; i< digitsSize + 1,我+ +){   ,,,,,,,,,,,newdigits[我]=0;   ,,,,,,,}   ,,,,,,,return  newdigits;   还有,,,}{   ,,,,,,,return 数字;   ,,,}   ,,   ,,,,   PS:}

迷迷糊糊就写完了.....不执行.....看了一下网上的程序貌似最后还要返回那个returnSize ..............这才可以。

其实只有全是9的时候才会产生首位进位...........

LeetCode066 + 1 C语言