res
.carry
to 0.p1
and p2
at the end of num1
and num2
respectively.p1
>= 0 or p2
>= 0:
a. Get the digit x1
from num1
at p1
or 0 if p1
< 0.
b. Get the digit x2
from num2
at p2
or 0 if p2
< 0.
c. Calculate the sum value = (x1 + x2 + carry) % 10
.
d. Update carry = (x1 + x2 + carry) / 10
.
e. Append value
to res
.
f. Decrement p1
and p2
.carry
is non-zero, append it to res
.res
.res
as a string.