leetcode 590.N-ary Tree Postorder Traversal N叉树的后序遍历
Posted Joel_Wang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 590.N-ary Tree Postorder Traversal N叉树的后序遍历相关的知识,希望对你有一定的参考价值。
递归方法
C++代码:
1 /* 2 // Definition for a Node. 3 class Node { 4 public: 5 int val; 6 vector<Node*> children; 7 8 Node() {} 9 10 Node(int _val, vector<Node*> _children) { 11 val = _val; 12 children = _children; 13 } 14 }; 15 */ 16 class Solution { 17 public: 18 vector<int> postorder(Node* root) { 19 vector<int>res; 20 post(root,res); 21 return res; 22 } 23 void post(Node*root, vector<int> &res){ 24 if(root==NULL) return; 25 for(int i=0;i<root->children.size();i++){ 26 post(root->children[i],res); 27 } 28 res.push_back(root->val); 29 } 30 };
以上是关于leetcode 590.N-ary Tree Postorder Traversal N叉树的后序遍历的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode&Python] Problem 590. N-ary Tree Postorder Traversal
leetcode590. N-ary Tree Postorder Traversal
(N叉树 递归) leetcode 590. N-ary Tree Postorder Traversal
[LeetCode] 590. N-ary Tree Postorder Traversal_Easy