privatestaticclassSolution{ public String addStrings(String num1, String num2){ StringBuilder res = new StringBuilder(); int left = num1.length() - 1; int right = num2.length() - 1; int carry = 0; while (left >= 0 || right >= 0) { int a = left >= 0 ? num1.charAt(left) - '0' : 0; int b = right >= 0 ? num2.charAt(right) - '0' : 0; int temp = a + b + carry; carry = temp / 10; res.append(temp % 10); left--; right--; } if (carry == 1){ res.append(1); }