class Solution:

# @param root, a tree link node

# @return nothing

def connect(self, root):

if not root:

return

root.next = None

level = [root]

while level:

for i in range(len(level)-1):

level[i].next = level[i+1]

level = [kid for l in level for kid in (l.left, l.right) if kid]