Skip to content

590. N 叉树的后序遍历 #90

@Geekhyt

Description

@Geekhyt

原题链接

递归 dfs

const postorder = function(root) {
    if (root === null) return []
    const res = []
    function dfs(root) {
        if (root === null) return;
        for (let i = 0; i < root.children.length; i++){
            dfs(root.children[i])
        }
        res.push(root.val)
    }
    dfs(root)
    return res
}
  • 时间复杂度: O(n)
  • 空间复杂度: O(n)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy