Login dark

https://leetcode-cn.com/problems/add-two-numbers/

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        plus = self.getNumber(l1) + self.getNumber(l2)
        return self.getListNode(plus)

    def getListNode(self, number):
        for i in range(len(str(number))):
            num = int(str(number)[i])
            if 0 == i:
                last = ListNode(int(num))
            else:
                ln = ListNode(int(num))
                ln.next = last
                last = ln
        return last

    def getNumber(self, ls: ListNode):
        ret = ''
        while True:
            ret = str(ls.val) + ret
            if ls.next == None:
                break
            else:
                ls = ls.next
        return int(ret)