Skip to content

Instantly share code, notes, and snippets.

@laricko
Created January 13, 2023 11:25
Show Gist options
  • Save laricko/702077ffb29e29177693c9905c07bf9b to your computer and use it in GitHub Desktop.
Save laricko/702077ffb29e29177693c9905c07bf9b to your computer and use it in GitHub Desktop.
LeetCode ListNode help methods
def list_node_to_list(l):
result = []
list_node = l
while list_node:
result.append(list_node.val)
list_node = list_node.next
return result
def list_to_list_node(l):
li = None
l.reverse()
for element in l:
list_node = ListNode(element, li)
li = list_node
return li
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment