Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def connect(self, root: 'Node') -> 'Node':
- head = root
- while head is not None:
- parent = head
- child = head = Node()
- while parent is not None:
- if parent.left is not None:
- child.next = parent.left
- child = child.next
- if parent.right is not None:
- child.next = parent.right
- child = child.next
- parent = parent.next
- head = head.next
- return root
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement