标签:
public class Solution { public int[] plusOne(int[] digits) { int carry = 1; int length = digits.length; List<Integer> list = new ArrayList<Integer>(); for (int i = length - 1; i >= 0; i--) { int digit = digits[i] + carry; if (digit > 9) { carry = 1; digit = digit - 10; } else { carry = 0; } list.add(digit); } if (carry != 0) { list.add(carry); } int[] result = new int[list.size()]; for (int i = 0; i < list.size(); i++) { result[list.size() - i - 1] = list.get(i); } return result; } }
标签:
原文地址:http://www.cnblogs.com/vision-love-programming/p/5038595.html