Zwei Zahlen hinzufügen Leetcode: Wo ist das Problem in meiner Lösung [geschlossen]Python

Python-Programme
Guest
 Zwei Zahlen hinzufügen Leetcode: Wo ist das Problem in meiner Lösung [geschlossen]

Post by Guest »

Meine Lösung für das Leetcode-Problem, zwei Zahlen hinzuzufügen, funktioniert in Jupyter Notebook und Google Colab, ich erhalte jedoch den folgenden Laufzeitfehler in Leetcode

Code: Select all

Runtime Error
TypeError: argument 2 to map() must support iteration
l1_num = int(''.join(list(map(str, l1))))
Line 14 in addTwoNumbers (Solution.py)
ret = Solution().addTwoNumbers(param_1, param_2)
Line 48 in _driver (Solution.py)
_driver()
Line 62 in  (Solution.py)
Leetcode-Fehler
Hier ist meine Lösung in Python:

Code: Select all

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution(object):
def addTwoNumbers(self, l1, l2):
"""
:type l1: Optional[ListNode]
:type l2: Optional[ListNode]
:rtype: Optional[ListNode]
"""

l1_num = int(''.join(list(map(str, l1))))
l2_num = int(''.join(list(map(str, l2))))
l_sum = str(l1_num + l2_num)

return [x for x in l_sum[::-1]]

Kann mir jemand helfen zu verstehen, warum ich diesen Fehler bei Leetcode erhalte und was die mögliche Lösung sein könnte?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post