标签:leetcode
https://oj.leetcode.com/problems/plus-one/
http://blog.csdn.net/linhuanmars/article/details/22365957
public class Solution { public int[] plusOne(int[] digits) { if (digits == null || digits.length == 0) return null; boolean carry = true; for (int i = digits.length - 1; i >= 0 ; i --) { int v = digits[i]; if (carry) v++; carry = v > 9; v = v % 10; digits[i] = v; } if (!carry) { return digits; } else { int[] r = new int[digits.length + 1]; r[0] = 1; for (int i = 1 ; i < r.length ; i ++) { r[i] = digits[i - 1]; } return r; } } }
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1598857