标签:描述 pre nod self tree printf [] 二叉树 from
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # 返回从上到下每个节点值列表,例:[1,2,3] def PrintFromTopToBottom(self, root): # write code here if not root: return [] queue = [] l = [] queue.append(root) while queue: node = queue.pop(0) l.append(node.val) if node.left: queue.append(node.left) if node.right: queue.append(node.right) return l
标签:描述 pre nod self tree printf [] 二叉树 from
原文地址:https://www.cnblogs.com/tianqizhi/p/9690101.html