Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
class Solution {
public:
int maxDepth(Node* root) {
if (!root) {
return 0;
}
int res = 1;
for (auto& x : root->children) {
res = max(res, maxDepth(x) + 1);
}
return res;
}
};