题目
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,则应该创建新节点,并赋值为1。 可以使用头结点,以方便while循环规则。
代码
1 | /** |