Maximum Depth of N-ary Tree LeetCode solution in C++
1class Solution {2public:3int maxDepth(Node *root) {4if (root == NULL) {5return 0;6}7int dep = 1, mx = INT_MIN;8helper(root, dep, mx);9return mx;10}1112void helper(Node *root, int dep, int &mx) {13if (root->children.size() == 0) {14mx = max(mx, dep);15}16for (int i = 0; i < root->children.size(); i++) {17helper(root->children[i], dep + 1, mx);18}19}20};