[leetcode] 559. Maximum Depth of N-ary Tree (easy)

it2025-11-19  11

原题链接

思路: 简单bfs

class Solution { public: int maxDepth(Node *root) { int depth = 0; if (root == NULL) return 0; queue<Node *> q; q.push(root); while (q.size() > 0) { depth++; int len = q.size(); for (int i = 0; i < len; i++) { vector<Node *> temp = q.front()->children; q.pop(); for (Node *n : temp) { q.push(n); } } } return depth; } };

转载于:https://www.cnblogs.com/ruoh3kou/p/9893439.html

相关资源:数据结构—成绩单生成器
最新回复(0)