大家好
超级新手想问问leecode一题
已经参考他人solution
但是遇到error: 'int' object is not iterable
想问问怎么改可以pass呢?
谢谢~~
题目如下:
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.
Code如下:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
string_1 = string_2 = ''
while l1:
string_1 += str(l1.val)
l1 = l1.next
while l2:
string_2 += str(l2.val)
l2 = l2.next
string_sum = str( int( string_1[::-1] ) + int( string_2[::-1] ) )
return [int(x) for x in string_sum[::-1]]
感谢大家~
solution不是我自己写的