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/
解题思路:
/** * @param {Node} root * @return {number[]} */ var postorder = function (root) { let result = []; // 保存结果 let stack = []; // 使用栈遍历 root && stack.push(root); // 二叉树存在时才开始遍历 // 遍历二叉树,直到清空栈,即为遍历了所有节点 while (stack.length) { // 从栈中弹出元素,顺序为从上到下,从右到左 const node = stack.pop(); // 将节点的值插入到结果数组的前端 // 保证了输出结果的顺序为从下到上,从左到右 result.unshift(node.val); // 将子节点按照从左到右入栈,保证了出栈顺序 if (node.children) { for (const child of node.children) { stack.push(child); } } } 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: