@@ -0,0 +1,1208 @@
+import java.util.Arrays;%0A%0Apublic class OnePlus %7B%0A    /**%0A    Given a non-negative number represented as an array of digits, plus one to the number.%0A    The digits are stored such that the most significant digit is at the head of the list.%0A    */%0A    public int%5B%5D plusOne(int%5B%5D digits) %7B%0A        int length = 0;%0A        int lastCarry = 1;%0A        int carry = 0;%0A        for (int i = digits.length - 1; i %3E= 0; i--) %7B%0A            carry = (digits%5Bi%5D + lastCarry) %3E= 10 ? 1 : 0;%0A            digits%5Bi%5D = (digits%5Bi%5D + lastCarry) %25 10;%0A            lastCarry = carry;%0A        %7D%0A        int newLength = (carry == 1) ? digits.length + 1 : digits.length;%0A        int%5B%5D result = new int%5BnewLength%5D;%0A        if (newLength == digits.length) %7B%0A            for (int i = 0; i %3C newLength; i++) %7B%0A                result%5Bi%5D = digits%5Bi%5D;%0A            %7D%0A        %7D else %7B%0A            result%5B0%5D = carry;%0A            for (int i = 0, j = 1; i %3C digits.length; i++, j++)%0A                result%5Bj%5D = digits%5Bi%5D;%0A        %7D%0A        return result;%0A    %7D%0A    %0A    public static void main (String%5B%5D args) %7B%0A        OnePlus test = new OnePlus ();%0A        int%5B%5D in = %7B9,9%7D;%0A        System.out.println(Arrays.toString(test.plusOne(in)));%0A    %7D%0A%7D

Add one to a number represented as an array of digits