Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- # Definition for a Node.
- class Node:
- def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):
- self.val = val
- self.left = left
- self.right = right
- self.next = next
- """
- class Solution:
- def connect(self, root: 'Optional[Node]') -> 'Optional[Node]':
- if not root or not root.left:
- return root
- root.left.next = root.right
- if root.next:
- root.right.next = root.next.left
- self.connect(root.left)
- self.connect(root.right)
- return root
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement