# LeetCode 2 Add Two Numbers

You are given two linked lists representing two non-negative numbers. 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.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

return l2 if l1.nil?

s1 = Array.new s2 = Array.new n = Array.new while l1 s1.unshift(l1.val) l1 = l1.next end while l2 s2.unshift(l2.val) l2 = l2.next end x = s1.join.to_i+s2.join.to_i n = x.to_s.chars.map(&:to_i) ans = ListNode.new(0) d = ans l = n.length() l.times do d.next = ListNode.new(n.pop) d = d.next end ans.next end

|
10月前
|

LeetCode刷题---Two Sum（一）
LeetCode刷题---Two Sum（一）
|
8月前
Leetcode 4. Median of Two Sorted Arrays

19 0
|
8月前
Leetcode 623. Add One Row to Tree

30 0
|
10月前
|

|

LeetCode - #2 Add Two Numbers

60 0
|

LeetCode - #1 Two Sum

45 0
LeetCode 167 Two Sum II - Input array is sorted（输入已排序数组，求其中两个数的和等于给定的数）

68 0
|
Python
LeetCode 21. 合并两个有序链表 Merge Two Sorted Lists
LeetCode 21. 合并两个有序链表 Merge Two Sorted Lists
79 0
LeetCode 1380. 矩阵中的幸运数 Lucky Numbers in a Matrix
LeetCode 1380. 矩阵中的幸运数 Lucky Numbers in a Matrix
124 0
|

LeetCode 350. 两个数组的交集 II ntersection of Two Arrays II
LeetCode 350. 两个数组的交集 II ntersection of Two Arrays II
90 0