class Solution {
public:
int maxDepth(Node* root) {
if (root == nullptr)return 0;
int depth = 0;
queue<Node*>q;
q.push(root);
while (!q.empty()) {
int size = q.size();
for (int i = 0; i < size; i++) {
Node* node = q.front();
q.pop();
for (Node* child : node->children)q.push(child);
}
depth++;
}
return depth;
}
};
N叉树的最大深度
最新推荐文章于 2022-03-06 17:05:16 发布