LeetCode 链表本地ide 内置函数 python

链表本体

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

列表转链表

def create_linked_list(arr:ListNode):
    head = ListNode(arr[0])
    cur = head
    for i in range(1, len(arr)):
        cur.next = ListNode(arr[i])
        cur = cur.next
    return head

输出存在内存地址的列表链表

def printList(l):
    while l:
        print("%d, " %(l.val), end = '')
        l = l.next
    print('')

简单调用

if __name__ == '__main__':
    a = Solution()
    head1 = create_linked_list(eval(input()))
    # head2 = create_linked_list([1, 3, 4])
    result = a.function(head1)
    printList(result)

另,ide debug也可查询变量

你可能感兴趣的:(链表,leetcode,数据结构)