mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -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)
|
return dfs(last, temp_next)
|
||||||
|
|
||||||
|
|
||||||
def flatten(head):
|
def flatten(head):
|
||||||
|
|
||||||
if head is None:
|
if head is None:
|
||||||
return head
|
return head
|
||||||
|
|
||||||
pseudo_head = Node(None, None, head, None)
|
sentinel = Node(None, None, head, None)
|
||||||
|
|
||||||
dfs(pseudo_head, head)
|
dfs(prev=sentinel, node=head)
|
||||||
pseudo_head.next.prev = None
|
|
||||||
|
|
||||||
return pseudo_head.next
|
# erase the pointer to sentinel and return
|
||||||
|
sentinel.next.prev = None
|
||||||
|
return sentinel.next
|
||||||
|
Loading…
x
Reference in New Issue
Block a user