★★
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 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 之外,这两个数字都不会以零开头。
1 | 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) |
从前往后加,主要是进位。
Java
1 | public class Solution { |
C++
1 | /** |
感觉隔了很久
最近堕落了( ̄~ ̄)