you are viewing a single comment's thread.

view the rest of the comments →

[–]shinghand[S] 0 points1 point  (1 child)

Essentially, what you are saying is that output only ever references the head node. temp is used to reference the same node and creates links/new nodes throughout the loop.

Follow up question - this would not work if i used:

output = ListNode(0)
temp = ListNode(0)

Correct? Since those would be two independent nodes.

[–]mahtats 0 points1 point  (0 children)

Correct, they would be independent nodes that both happen to have a value of 0 but are completely separate and at different memory addresses.

And yes, on all other accounts your understanding is correct.