begeekmyfriend/leetcode

add_two_sum have something wrong

kironys opened this issue · 1 comments

You convert it to reverse order before adding, but the carry should be given to the previous one.for example:243+563->342+365=707. in your code it's 608

Well according to the problem, the digital shall be stored in the link reversely. For instance, if we want the sum of 243 and 563, the storage in the two links should be as follows:

3 -> 4 -> 2
3 -> 6 -> 5

And the sum is 806 and to be stored as follows:

6 -> 0 -> 8

If we want the sum of 342 + 365, then the storage in those links are as follows:

2 -> 4 -> 3
5 -> 6 -> 3
7 -> 0 -> 7