Given a n-ary tree, find its maximum depth.
    The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
    For example, given a 3-ary tree:
    559. Maximum Depth of N-ary Tree - 图1


    We should return its max depth, which is 3.

    Note:

    1. The depth of the tree is at most 1000.
    2. The total number of nodes is at most 5000.

    Runtime: 44 ms, faster than 73.95% of C++ online submissions for Maximum Depth of N-ary Tree.

    1. /*
    2. // Definition for a Node.
    3. class Node {
    4. public:
    5. int val;
    6. vector<Node*> children;
    7. Node() {}
    8. Node(int _val, vector<Node*> _children) {
    9. val = _val;
    10. children = _children;
    11. }
    12. };
    13. */
    14. class Solution {
    15. public:
    16. int maxDepth(Node* root) {
    17. if (root == NULL) {
    18. return 0;
    19. }
    20. int size = root->children.size();
    21. if (size < 1) {
    22. return 1;
    23. }
    24. int max = 0;
    25. for (auto node: root->children) {
    26. int temp = maxDepth(node);
    27. if (temp > max) {
    28. max = temp;
    29. }
    30. }
    31. return ++max;
    32. }
    33. };