Skip to content

Commit 83204ed

Browse files
authored
559 Maximum Depth of N-ary Tree
559 Maximum Depth of N-ary Tree
1 parent 53944de commit 83204ed

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maxDepthn.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int maxDepth(Node* root) {
4+
if (root==NULL) return 0;
5+
int maxl = 1;
6+
for(int i = 0; i < root->children.size(); i++) {
7+
if(root->children[i]) {
8+
maxl = max(maxl, 1+ maxDepth(root->children[i]));
9+
}
10+
}
11+
return maxl;
12+
}
13+
};

0 commit comments

Comments
 (0)