題目概述:
given a non-negative number represented as an array of digits, plus one to the number.
the digits are stored such that the most significant digit is at the head of the list.
題目解析:
給你一個int型數組存儲一個非負整數,對整數加1後輸出一個int型數組。注意幾點:
1.可能存在進位操作,增加一位,如999+1=1000;
2.數組存儲如234=[2, 3, 4],它進行加1操作時從數組的高位(4)到低位(2);
3.輸出時也需要轉置[0, 0, 0, 1]轉成1000;
4.c語言代碼*returnsize是一維數組,注意指派否則提示“逾時異常”。
我的代碼:
推薦代碼:
c++代碼
同類題目:
ps:需要注意轉換方法 ((a[i]-'0')+(b[j]-'0')+add)%2+'0'目前結果和進位數字add=((a[i]-'0')+(b[j]-'0')+add)/2;同時需要注意字元串倒置的方法和對齊判斷即可。