Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def flatten(self, head: 'Node') -> 'Node':
- if head is None:
- return None
- prev = None
- to_process = [head]
- while to_process:
- cur = to_process.pop()
- if cur.next:
- to_process.append(cur.next)
- if cur.child:
- to_process.append(cur.child)
- cur.child = None
- cur.prev = prev
- if prev:
- prev.next = cur
- prev = cur
- return head
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement