Created
January 13, 2023 11:25
-
-
Save laricko/702077ffb29e29177693c9905c07bf9b to your computer and use it in GitHub Desktop.
LeetCode ListNode help methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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