LeetCode 2 - Add Two Numbers
Difficulty: medium
Problem Description
English (Add Two Numbers)
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 contains a single digit. Add the two numbers and return the sumas a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Example 1:
graph LR
node11((2))
node12((4))
node13((3))
node11 ---> node12 ---> node13
node21((5))
node22((6))
node23((4))
node21 ---> node22 ---> node23
node31((7))
node32((0))
node33((8))
node31 ---> node32 ---> node33
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
Constraints:
- The number of nodes in each linked list is in the range
[1, 100]
. 0 <= Node.val <= 9
- It is guaranteed that the list represents a number that does not have leading zeros.
Chinese (两数相加)
给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。
请你将两个数相加,并以相同形式返回一个表示和的链表。
你可以假设除了数字 0 之外,这两个数都不会以 0 开头。
示例 1:
graph LR
node11((2))
node12((4))
node13((3))
node11 ---> node12 ---> node13
node21((5))
node22((6))
node23((4))
node21 ---> node22 ---> node23
node31((7))
node32((0))
node33((8))
node31 ---> node32 ---> node33
1 |
|
示例 2:
1 |
|
示例 3:
1 |
|
提示:
- 每个链表中的节点数在范围
[1, 100]
内 0 <= Node.val <= 9
- 题目数据保证列表表示的数字不含前导零
Solution
C++
1 |
|
LeetCode 2 - Add Two Numbers
http://wasprime.github.io/Algorithm/LeetCode/LinkedList/LeetCode-2-Add-Two-Numbers/