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
}
};

浙公网安备 33010602011771号