Leetcode590 N叉树的后序遍历

~~// /*递归法
// // Definition for a Node.
// 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==nullptr)
	return res;
for(int i=0;i<root->children.size();i++)
{
	postorder(root->children[i]);

}
	res.push_back(root->val);
	return res;
}

相关文章:

  • 2021-04-19
  • 2021-11-26
  • 2021-11-26
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-10-13
猜你喜欢
  • 2022-01-14
  • 2021-06-17
  • 2021-05-06
  • 2021-12-26
  • 2022-12-23
  • 2022-02-03
  • 2021-09-28
相关资源
相似解决方案