445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Follow up:
What if you cannot modify the input lists? In other words, reversing the lists is not allowed.
Example:
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Follow up:
What if you cannot modify the input lists? In other words, reversing the lists is not allowed.
Example:
Input: (7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 8 -> 0 -> 7
两个数相加
您将获得两个非空链表,表示两个非负整数。最重要的数字首先出现,每个节点包含一个数字。添加两个数字并将其作为链接列表返回。
您可以假设这两个数字不包含任何前导零,除了数字0本身。
思路:把两个链表遍历存入Stack中,对两个 Stack 顶层的数加和 %10。如果大于 10 下一位加的时候 +1 。
卧槽这题把我搞死了。。。