/***
 * Given a non-negative number represented as an array of digits, plus one to the number.
 *
 * The digits are stored such that the most significant digit is at the head of the list.
 */
public class Solution {
    public int[] plusOne(int[] digits) {
        int n = digits.length;
        if (n == 0)
            return null;
        int addup = 0;
        if (digits[n - 1] + addup + 1 >= 10) {
            digits[n - 1] += addup + 1 - 10;
            addup = 1;
        } else {
            digits[n - 1] += addup + 1;
            addup = 0;
        }

        for (int i = n - 2; i >= 0; i--){
            if (digits[i] + addup >= 10) {
                digits[i] += addup - 10;
                addup = 1;
            } else {
                digits[i] += addup;
                addup = 0;
            }
        }

        if (addup == 1) {
            int newdigits[] = new int[n + 1];
            newdigits[0] = 1;
            for (int i = 2; i <= n; i++)
                newdigits[i] = digits[i - 1];
            return newdigits;
        } else
            return digits;

    }
}


@@ -294,271 +294,21 @@
    i
-f (n == 0)%0A            return null;%0A        int addup = 0;%0A        if (digits%5Bn - 1%5D + addup + 1 %3E= 10) %7B%0A            digits%5Bn - 1%5D += addup + 1 - 10;%0A            addup = 1;%0A        %7D else %7B%0A            digits%5Bn - 1%5D += addup + 1;%0A            addup = 0;%0A        %7D
+nt addup = 1;
 %0A%0A  
@@ -330,17 +330,17 @@
 i = n - 
-2
+1
 ; i %3E= 0
@@ -435,35 +435,8 @@
 10;%0A
-                addup = 1;%0A
     
@@ -537,15 +537,8 @@
     
-    %7D%0A%0A
     
@@ -558,17 +558,53 @@
  == 
-1) %7B%0A    
+0)%0A                return digits;%0A        %7D%0A%0A
     
@@ -641,36 +641,32 @@
 n + 1%5D;%0A        
-    
 newdigits%5B0%5D = 1
@@ -671,28 +671,24 @@
  1;%0A        
-  
-  
 for (int i =
@@ -704,20 +704,16 @@
 n; i++)%0A
-    
         
@@ -750,28 +750,24 @@
 1%5D;%0A        
- 
-   
 return newdi
@@ -775,50 +775,8 @@
 its;
-%0A        %7D else%0A            return digits;
 %0A%0A  

add PlusOne.java