# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
# 返回二维列表[[1,2],[4,5]]
def Print(self, pRoot):
# write code here
if not pRoot:
return []
res=[]
tmp=[pRoot]
tmp1=[]
mid=[]
while tmp:
for i in tmp:
mid.append(i.val)
if i.left:
tmp1.append(i.left)
if i.right:
tmp1.append(i.right)
res.append(mid)
tmp=tmp1
tmp1=[]
mid=[]
return res
剑指offer-把二叉树打印成多行(python)
最新推荐文章于 2022-04-06 20:04:19 发布