0ms Java Solution


  • 1
    public class Solution {
    		public int[] plusOne(int[] digits) {
    			int i = digits.length - 1;
    			if (digits[i] < 9)
    				digits[i]++;
    			else {
    				for (; i >= 0 && digits[i] == 9; --i)
    					digits[i] = 0;
    				if (digits[0] == 0) {
    					digits = new int[digits.length + 1];
    					digits[0] = 1;
    				} else
    					digits[i]++;
    			}
    			return digits;
    		}
    	}

Log in to reply
 

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