415. Add Strings
class Solution {
public String addStrings(String num1, String num2) {
StringBuilder builder = new StringBuilder();
int carry = 0;
int i = num1.length() - 1;
int j = num2.length() - 1;
while (i >= 0 || j >= 0) {
int iNum = (i >= 0) ? num1.charAt(i) - '0' : 0;
int jNum = (j >= 0) ? num2.charAt(j) - '0' : 0;
int sum = iNum + jNum + carry;
carry = sum / 10;
builder.append(sum % 10);
i--;
j--;
}
if (carry == 1) {
builder.append(1);
}
return builder.reverse().toString();
}
}