415. Add Strings

easy

Example 1:

Input: num1 = "11", num2 = "123"
Output: "134"

Example 2:

Input: num1 = "456", num2 = "77"
Output: "533"

Example 3:

Input: num1 = "0", num2 = "0"
Output: "0"

Solution

class Solution {
public:
string addStrings(string num1, string num2) {
int carry = 0;
int i = num1.size() - 1;
int j = num2.size() - 1;
string result;
while (i >= 0 || j >= 0 || carry) {…