题目:
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
1. 存储是反过来的,(2 -> 4 -> 3)存储的是342,(5 -> 6 -> 4)存储的是465;
2.链表l1或l2为空时,直接返回,这是边界条件,省掉多余的操作;
3.链表l1和l2长度可能不同,因此要注意处理某个链表剩余的高位;
4.进位是向后的,进位数为0时不用进位,不为零时需要向后进位,最高位不为零时需要增加节点进位;
代码(Java):