题解 | #牛群仰视图#先序遍历所有节点,找到叶子结点

牛群仰视图

https://www.nowcoder.com/practice/0f37a18320c4466abf3a65819592e8be

# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param root TreeNode类 
# @return int整型一维数组
#
class Solution:
    def bottomView(self , root: TreeNode) -> List[int]:
        # write code here
        res=[]
        def preOrder(root,res):
            if(root==None):
                return res
            if(root.left==None and root.right==None):
                res.append(root.val)
            preOrder(root.left,res)
            preOrder(root.right,res)
            return res

        ans=preOrder(root,res)
        return ans

        



全部评论

相关推荐

VirtualBool:都去逗他了?
点赞 评论 收藏
分享
05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务