标签:
这个题目与java里的BigInteger实现有些类似,可以参考其源码。
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.
public class Solution { public int[] plusOne(int[] digits) { for(int i=digits.length-1;i>=0;i--){ int temp=digits[i]+1; if(temp>=10){ digits[i]=temp%10; }else{ digits[i]=temp; break; } } if(digits[0]==0){ int[] re=new int[digits.length+1]; re[0]=1; for(int j=1;j<re.length;j++){ re[j]=digits[j-1]; } return re; } return digits; } }
标签:
原文地址:http://blog.csdn.net/wj512416359/article/details/42245191