Leetcode 002: Add Two Numbers

Solution:

Leetcode 002: Add Two Numbers

Idea:

Since the length of two linked list may be different, we firstly add up each node in the two list until one reaches the end.

Then because we do not know which linked list reaches the end, we iterate both list (the finished list will not enter the loop statement), and add up the node with the carry c.

In the end, we need to check whether the carry c is 0 or 1. If it is 1, then we need to add one more node to the result.

This problem is not difficult and requires a bit more carefulness.