标签:turn style nbsp queue tmp div class roo 打印二叉树
1 class Solution: 2 # 返回二维列表[[1,2],[4,5]] 3 def Print(self, pRoot): 4 # write code here 5 if pRoot==None: 6 return [] 7 queue1=[pRoot] 8 queue2=[] 9 res = [] 10 while queue1 or queue2: 11 if queue1: 12 tmpRet = [] 13 while queue1: 14 tmpNode=queue1.pop(0) 15 tmpRet.append(tmpNode.val) 16 if tmpNode.left: 17 queue2.append(tmpNode.left) 18 if tmpNode.right: 19 queue2.append(tmpNode.right) 20 res.append(tmpRet) 21 if queue2: 22 tmpRet = [] 23 while queue2: 24 tmpNode = queue2.pop(0) 25 tmpRet.append(tmpNode.val) 26 if tmpNode.left: 27 queue1.append(tmpNode.left) 28 if tmpNode.right: 29 queue1.append(tmpNode.right) 30 res.append(tmpRet) 31 return res
2020-01-01 18:53:24
标签:turn style nbsp queue tmp div class roo 打印二叉树
原文地址:https://www.cnblogs.com/NPC-assange/p/12129523.html