<pre name="code" class="python">class Solution:
# @param root, a tree node
# @return a list of lists of integers
def levelOrder(self, root):
queue=[]
l=[]
if root:
queue.append(root)
while len(queue)>0:
length=len(queue)
tempList=[]
while length>0:
tempNone=queue.pop()
length-=1
tempList.append(tempNone.val)
if tempNone.left!=None:
queue.insert(0,tempNone.left)
if tempNone.right!=None:
queue.insert(0,tempNone.right)
l.append(tempList)
return l
else:
return l
Python学习——leetcode(Binary Tree Level Order Traversal)
最新推荐文章于 2019-05-28 11:08:57 发布