题解 | #二叉树的后序遍历#

二叉树的后序遍历

https://www.nowcoder.com/practice/1291064f4d5d4bdeaefbf0dd47d78541

export function postorderTraversal(root: TreeNode): number[] {
    // write code here
    const res = []
    function traversal(root){
        if(root){
            // push在这里是前序遍历
            traversal(root.left);
            // push在这里是中序遍历
            traversal(root.right)
            // push放在这里是后续遍历
            res.push(root.val)
        }
    }
    traversal(root)
    return res
}

全部评论

相关推荐

牛客66512506...:那个百度acg是不是个小哥啊,老是问些底层问题狠狠为难,然后kpi
哪些公司在招寒假实习?
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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