Java solution Using Math


  • 0
    Y
     public int[] plusOne(int[] digits) {
         int i=digits.length-1;
        while(i>=0){
        	if(digits[i]+1<10) {
        		digits[i]+=1;
        		return digits;
        	}
        	if(digits[i]+1==10){
        		digits[i]=0;
        		i--;
        	}
        }
        int [] result=new int[digits.length+1];
        result[0]=1;
        return result;
    }

Log in to reply
 

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