-
Notifications
You must be signed in to change notification settings - Fork 0
/
116.py
26 lines (24 loc) · 785 Bytes
/
116.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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):
if root is not None:
self.parseLevel([root])
def parseLevel(self, parselist):
for i in range(len(parselist)-1):
parselist[i].next = parselist[i+1]
nextlist = []
if parselist[0].left is not None:
for i in range(len(parselist)):
nextlist.append(parselist[i].left)
nextlist.append(parselist[i].right)
self.parseLevel(nextlist)
solu = Solution()
solu.connect(None)