python将字符串/列表创建链表

code

class ListNode:
    def __init__(self,x):
        self.val=x
        self.next=None
 
def listToListNode(input):
    # Generate list from the input
    numbers = [int(x) for x in input().split()]
 
    # Now convert that list into linked list
    new = ListNode(0)
    head = new
    for number in numbers:
        head.next = ListNode(number)
        head = head.next
    return new.next

原文地址:https://www.cnblogs.com/sea-stream/p/14181094.html