LeetCode 559 n叉树的最大深度

class Solution {
public:
    int maxDepth(Node* root) {
        if (root == nullptr) return 0;

        int depth = 0;
        for (int i = 0; i < root->children.size(); i ++) {
            depth = max(depth, maxDepth(root->children[i]));
        }

        return depth + 1; //每层+1
    }
};
posted @ 2022-09-07 09:26  hjy94wo  阅读(19)  评论(0)    收藏  举报