当前位置: 首页 > 后端技术 > PHP

LeetcodePHP解答--D42559.N叉树的最大深度

时间:2023-03-29 18:58:43 PHP

D42559.N叉树的最大深度题目链接559.N叉树的最大深度题目分析这道题思路和上一题一样一。只是不是二叉树。而是一棵普通的树。思路略最终代码level++;如果($this->level>=$this->max){$this->max=$this->level;}}if($root->children){foreach($root->childrenas$child){$this->maxDepth($child);}}if($root){$this->level--;}返回$this->max;}}如果您觉得本文对您有用,欢迎使用iGeneration支持。