Advertisement
Guest User

Untitled

a guest
May 24th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class Solution:
  2. # @param root, a tree link node
  3. # @return nothing
  4. def connect(self, root):
  5. if not root: return
  6. cur = [root]
  7. next = []
  8. while len(cur) != 0:
  9. for i in range(len(cur)):
  10. if i != len(cur) - 1: cur[i].next = cur[i+1]
  11. if cur[i].left: next.append(cur[i].left)
  12. if cur[i].right: next.append(cur[i].right)
  13. if len(next) != 0:
  14. cur = next
  15. next = []
  16. else: return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement