mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
Update flatten_list.py
This commit is contained in:
parent
ea12ccce74
commit
85f1f87c8d
@ -27,14 +27,15 @@ def dfs(prev, node):
|
||||
return dfs(last, temp_next)
|
||||
|
||||
|
||||
def flatten(head):
|
||||
def flatten(head):
|
||||
|
||||
if head is None:
|
||||
return head
|
||||
|
||||
pseudo_head = Node(None, None, head, None)
|
||||
|
||||
dfs(pseudo_head, head)
|
||||
pseudo_head.next.prev = None
|
||||
|
||||
return pseudo_head.next
|
||||
sentinel = Node(None, None, head, None)
|
||||
|
||||
dfs(prev=sentinel, node=head)
|
||||
|
||||
# erase the pointer to sentinel and return
|
||||
sentinel.next.prev = None
|
||||
return sentinel.next
|
||||
|
Loading…
x
Reference in New Issue
Block a user