首页 > 代码库 > [LeetCode] Plus One

[LeetCode] Plus One

public class Solution {    public int[] plusOne(int[] digits) {        for (int i=digits.length-1; i>=0; i--) {            if (digits[i] != 9) {                digits[i] = digits[i] + 1;                return digits;            } else {                digits[i] = 0;            }        }                // 说明overflow了,此时原数组全是9        int [] result = new int[digits.length+1];        result[0] = 1;        for (int i=1; i<result.length; i++)            result[i] = 0;        return result;    }}    

 

[LeetCode] Plus One