难度水平:中等
描述
已知两个非负整数(例如:l1 = 342,l2 = 465),将数字分别按相反的顺序存储到链表中(例如:l1 = [2,4,3],l2 = [5,6,4]),每个节点都包含一个数字...示例
示例
输入:l1 = [2,4,3],l2 = [5,6,4]
产出:[7,0,8]
说明:342 + 465 = 807
示例 2
输入:l1 = [0],l2 = [0]
产出:[0]...示例 3
输入:l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
产出:[8,9,9,9,0,0,0,1]
限制
每个链表中的节点数在 [1, 100] 范围内
0 <= 节点值...{
guard let l1 = l1 else {return l2}
guard let l2 = l2 else {return l1}...let outputNode = ListNode((l1.val + l2.val)%10)
if l1.val + l2.val > 9 {
outputNode.next