Java Solution


  • 0
    D

    public class Solution {

    public int[] plusOne(int[] digits) {
        int i = digits.length - 1;
        while (i >= 0 && digits[i] == 9) i--;
        int[] res = new int[digits.length + (i < 0 ? 1 : 0)];
        for (int j = 0; j <= i; j++) res[j] = digits[j];
        res[i < 0 ? 0 : i]++;
        return res;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.