You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//LINK TO THE PROBLEM :- https://leetcode.com/problems/maximum-depth-of-n-ary-tree/
2
+
/*
3
+
// Definition for a Node.
4
+
class Node {
5
+
public:
6
+
int val;
7
+
vector<Node*> children;
8
+
9
+
Node() {}
10
+
11
+
Node(int _val) {
12
+
val = _val;
13
+
}
14
+
15
+
Node(int _val, vector<Node*> _children) {
16
+
val = _val;
17
+
children = _children;
18
+
}
19
+
};
20
+
*/
21
+
22
+
/*EXPLANATION :- We will be using here simple DFS the only difference being that there is no visited array as we have in case of graphs normally. The height() func takes two parameters root of the N-ary tree and initial height which is passed as 0 and the height increases as we mive further down the tree for every leaf node we calculate the max. depth so far for all the leaves*/
0 commit comments