class Solution(object):
def addTwoNumbers(self, l1, l2):
c1, c2 = '', ''
while l1:
c1 += str(l1.val)
l1 = l1.next
while l2:
c2 += str(l2.val)
l2 = l2.next
num = str(int(c1) + int(c2))
dummy = ListNode(0)
c = dummy
for i in range(len(num)):
c.next = ListNode(num[i])
c = c.next
return dummy.next
Naive Python Solution



@lilixu Someone told me about it when I shared them the original question (this one is part2). But you can imagine if a language had a method called add_two_linkedlist. Is there really a point to show the solution is return add_two_linkedlist(l1, l2)? You can check out the editoral comments for what the spirit of the question is https://leetcode.com/articles/addtwonumbers/

@lilixu I agree with lucidsushi's opinion. According to the level of difficulty of this question, a medium level, one of test points should be how to manipulate singly linked lists to achieve the goal of summation of two lists; the other one point to check is how to use dfs idea to design your algorithm for this question. Your algorithm design is pretty easy, because all builtin Python functions you use in your code hide the test points. If you are preparing for technical interview, you should try not to use builtin Python functions in your solution. For easy level questions, you could use them.