给定一个 N 叉树,返回其节点值的后序遍历。

class Node {
public:
int val;
vector<Node*> children; Node() {} Node(int _val, vector<Node*> _children) {
val = _val;
children = _children;
}
}; class Solution {
public:
vector<int> res;
vector<int> postorder(Node* root)
{
if(root == NULL)
return res;
Fun(root);
return res;
} void Fun(Node* root)
{
if(root == NULL)
return;
int len = root ->children.size();
for(int i = 0; i < len; i++)
{
if(root ->children[i] != NULL)
Fun(root ->children[i]);
}
res.push_back(root ->val);
}
};

Leetcode590N-ary Tree Postorder TraversalN叉树的后序遍历的更多相关文章

  1. [LeetCode] Binary Tree Postorder Traversal 二叉树的后序遍历

    Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...

  2. leetcode题解:Binary Tree Postorder Traversal (二叉树的后序遍历)

    题目: Given a binary tree, return the postorder traversal of its nodes' values. For example:Given bina ...

  3. lintcode:Binary Tree Postorder Traversal 二叉树的后序遍历

    题目: 二叉树的后序遍历 给出一棵二叉树,返回其节点值的后序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [3,2,1] 挑战 你能使用非递归实现么? 解题: 递归程序 ...

  4. LeetCode 145. Binary Tree Postorder Traversal 二叉树的后序遍历 C++

    Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [,,] \ / O ...

  5. C++版 - LeetCode 145: Binary Tree Postorder Traversal(二叉树的后序遍历,迭代法)

    145. Binary Tree Postorder Traversal Total Submissions: 271797 Difficulty: Hard 提交网址: https://leetco ...

  6. LeetCode 145. Binary Tree Postorder Traversal二叉树的后序遍历 (C++)

    题目: Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [1,nul ...

  7. [LeetCode] 145. Binary Tree Postorder Traversal 二叉树的后序遍历

    Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...

  8. 【LeetCode】Binary Tree Postorder Traversal(二叉树的后序遍历)

    这道题是LeetCode里的第145道题. 题目要求: 给定一个二叉树,返回它的 后序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [3,2,1] 进阶: 递归算法很 ...

  9. 145 Binary Tree Postorder Traversal 二叉树的后序遍历

    给定一棵二叉树,返回其节点值的后序遍历.例如:给定二叉树 [1,null,2,3],   1    \     2    /   3返回 [3,2,1].注意: 递归方法很简单,你可以使用迭代方法来解 ...

随机推荐

  1. Docker这个新软件究竟是用来干嘛的???

    http://dockone.io/article/378 尝试新软件 对开发者而言,每天会催生出的各式各样的新技术都需要尝试,然而开发者却不太可能为他们一一搭建好环境并进行测试.时间非常宝贵,正是得 ...

  2. 解决git每次输入密码,设置gitlab、github默认push的用户名和密码

    git ssh key配置&解决git每次输入密码   欢迎加入qq群(IT-程序猿-技术交流群):757345416 在使用git时,每次pull/push都需要输入密码,有时大大降低了我们 ...

  3. express 4 使用session和cookies

    https://my.oschina.net/u/1466553/blog/294336 http://blog.csdn.net/liyi109030/article/details/3527138 ...

  4. Hibernate 查询语言

    查询语言 Hibernate 查询语言(HQL)是一种面向对象的查询语言,类似于 SQL,但不是去对表和列进行操作,而是面向对象和它们的属性. HQL 查询被 Hibernate 翻译为传统的 SQL ...

  5. 数据库insert和update

    1.当使用insert时不能使用where id=?,这是要使用update语句 2.只对一些列插入数据或者更新数据: insert是: insert tb(column1,column2..)val ...

  6. DSP using MATLAB》Problem 8.16

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  7. css 超出两行省略号,超出一行省略号

    参考:https://www.cnblogs.com/yangguojin/p/10301981.html 超出一行省略: p{ white-space:nowrap; overflow:hidden ...

  8. elasticsearch 中文API 获得(三)

    获取API 获取API允许你通过id从索引中获取类型化的JSON文档,如下例: GetResponse response = client.prepareGet("twitter" ...

  9. DROOLS通过URL访问changset

    package droolsRule; import java.net.Authenticator; import java.net.PasswordAuthentication; import ka ...

  10. fstream文件打开模式

    fstream:对于文件的操作很久两年前就开始使用了,但是仅仅为了达到满足自己需求的目的,就是要么是写,要么是读.从来没有对其进行详细的了解.自己也曾经想过花一点时间去总结一下,这个东西到底应该怎么用 ...