# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # self.next = None class Solution: # @param root, a tree node # @return nothing def connect(self, root): crt=root while crt: firstNextLevel=None prev=None while crt: if not firstNextLevel: firstNextLevel=crt.left if crt.left else crt.right if crt.left: if prev: prev.next=crt.left prev=crt.left if crt.right: if prev: prev.next=crt.right prev=crt.right crt=crt.next crt=firstNextLevel
Tuesday, September 9, 2014
Leetcode: Populating Next Right Pointers in Each Node II @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment