How Does Self.next = None Get The Next Value Of L1?
I was working on one of the problems on Leetcode (problem 21). It asks me to merge two sorted linked lists and return it as a new list, and it gives pre-typed code like this. # Def
Solution 1:
That None
is the default value of next
in a new ListNode
. Other ListNode
s can have other values assigned to next
. Constructing a properly linked list of ListNodes
involves assigning to each node's link parameter a reference to the next node:
l1 = ListNode(1)
l2 = ListNode(2)
l3 = ListNode(3)
l4 = ListNode(4)
l5 = ListNode(5)
l1.next = l2
l2.next = l3
l3.next = l4
l4.next = l5
Post a Comment for "How Does Self.next = None Get The Next Value Of L1?"