We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接:https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/
解题思路:
/** * // Definition for a Node. * function Node(val,children) { * this.val = val; * this.children = children; * }; */ function recursion(node, res) { // 若节点为空,则退出 if (!node) { return; } // 递归遍历所有子节点 for (let i = 0; i < node.children.length; i++) { recursion(node.children[i], res); } // 后续遍历,即为在遍历完所有子节点之后,存储当前节点的值 res.push(node.val); } /** * @param {Node} root * @return {number[]} */ var postorder = function (root) { let result = []; // 保存结果 // 递归遍历二叉树 recursion(root, result); return result; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接:https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/
解题思路:
The text was updated successfully, but these errors were encountered: