590. N叉树的后序遍历
地址:https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/
/** * Definition for a Node. * class Node { * public $val = null; * public $children = null; * function __construct($val = 0) { * $this->val = $val; * $this->children = array(); * } * } */ class Solution { /** * @param Node $root * @return integer[] */ function postorder($root) { $res = []; $this->helper($root,$res); $res[]=$root->val; return $res; } function helper($root,&$res){ if($root == null) return ; foreach($root->children as $children){ $this->helper($children,$res); $res[]= $children->val; } } }