Array:plusOne

public int[] plusOne(int[] digits) { int jinwei = 1; for (int i = digits.length - 1; i >= 0; i--) { int temp = (digits[i] + jinwei) / 10; digits[i] = (digits[i] + jinwei) % 10; jinwei = temp; } if (jinwei == 0) { return digits; } else { int[] nums = new int[digits.length + 1]; nums[0] = 1; for (int i = 1; i < nums.length; i++) { nums[i] = digits[i - 1]; } return nums; } }

    推荐阅读