LeetCode题解之Maximum Depth of N-ary Tree

1、题目描述

 

2、问题分析

利用递归fangf

3、代码

 1 int maxDepth(Node* root) {
 2         int res = maxdep(root);
 3         return res;
 4     }
 5     
 6     int maxdep(Node *root)
 7     {
 8         if (root == NULL)
 9             return 0;
10         else {
11             int res = 1;
12             for (auto child : root->children) {
13                 res = max(res,maxdep(child)+1);
14             }
15             return res;
16         }
17     }

 

posted @ 2019-02-24 10:18  山里的小勇子  阅读(94)  评论(0编辑  收藏  举报