算法第二题:
You are given two non-empty linked lists representing two non-negative integers.
给两个表示非负整数的非空链表
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.
将两个数字相加并以链表返回。
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
你可以假定每个数字不包含任何前导零,除非0本身。
Example:
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.
my solution我的解法:
1 | /** |
Runtime: 19 ms, faster than 99.14% of Java online submissions for Add Two Numbers.
Memory Usage: 47.7 MB, less than 47.01% of Java online submissions for Add Two Numbers.
Most Vote Solution投票最多的解法:
1 | /** |
Runtime: 20 ms, faster than 80.39% of Java online submissions for Add Two Numbers.
Memory Usage: 48.4 MB, less than 6.94% of Java online submissions for Add Two Numbers.