leetcode层序遍历二叉树 - 102
给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。
示例:
二叉树:[3,9,20,null,null,15,7],
res=[]
if not root:
return res
def haha(root,depth):
if not root:
return
if depth == len(res):
res.append([])
res[depth].append(root.val)
haha(root.left,depth+1)
haha(root.right,depth+1)
haha(root,0)
return res
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/binary-tree-level-order-