Leecode 559. N 叉树的最大深度 递归

阅读 65

2022-05-02

原题链接:Leecode 559. N 叉树的最大深度
在这里插入图片描述在这里插入图片描述

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

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    int maxDepth(Node* root) {
        if(!root) return 0;
        if((root->children.size()==0)) return 1;
        int h=INT_MIN;
        for(int i=0;i<root->children.size();i++)
            h=max(h,maxDepth(root->children[i]));
        return h+1;
    }
};

精彩评论(0)

0 0 举报