forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0117.py
More file actions
23 lines (20 loc) · 649 Bytes
/
Copy path0117.py
File metadata and controls
23 lines (20 loc) · 649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Definition for binary tree with next pointer.
class TreeLinkNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
self.next = None
class Solution:
# @param root, a tree link node
# @return nothing
def connect(self, root):
while root:
node = dummy = TreeLinkNode(0)
while root:
if root.left:
node.next = node = root.left
if root.right:
node.next = node = root.right
root = root.next
root = dummy.next