public String add(String num1, String num2) {
        // Start typing your Java solution below
        // DO NOT write main() function
        char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        if (num1 == null || num1.length() == 0) {
            return num2;
        }
        if (num2 == null || num2.length() == 0) {
            return num1;
        }

        int carry = 0;
        StringBuffer sb = new StringBuffer();
        int end1 = num1.length() - 1;
        int end2 = num2.length() - 1;
        while (end1 >= 0 || end2 >= 0) {
            if (end1 >= 0) {
                carry += (int) (num1.charAt(end1) - '0');
            }
            if (end2 >= 0) {
                carry += (int) (num2.charAt(end2) - '0');
            }
            sb.append(digits[carry % 10]);
            carry = carry / 10;
            end1--;
            end2--;
        }
        if (carry != 0) {
            sb.append(digits[carry]);
        }
        return sb.reverse().toString();
    }