# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param root, a tree node # @return a list of lists of integers def levelOrder(self, root): crt=[root] rst=[] if not crt: return [] while crt!=[None]*len(crt): rst.append([i.val for i in crt]) nextlvl=[] for i in crt: if i.left: nextlvl.append(i.left) if i.right: nextlvl.append(i.right) crt=nextlvl return rst
Tuesday, September 9, 2014
Leetcode: Binary Tree Level Order Traversal @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment