Skip to content

559. Maximum Depth of N-ary Tree #283

@namespace-io

Description

@namespace-io
/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/
class Solution {
public:
    int maxDepth(Node* root) {
        if(root == nullptr) return 0;
        int r = 0;
        for(auto node : root->children){
            r = max(maxDepth(node), r);
        }
        
        return r + 1;
    }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions