Leetcode 104. Maximum Depth of Binary Tree
문제 : 104. Maximum Depth of Binary Tree
등급 : Easy
class Solution {
int stepDown(TreeNode * root, int depth) {
if (!root) return depth;
depth += 1;
auto ldepth = stepDown(root->left, depth);
auto rdepth = stepDown(root->right, depth);
depth = std::max(depth, ldepth);
depth = std::max(depth, rdepth);
return depth;
}
public:
int maxDepth(TreeNode* root) {
return stepDown(root, 0);
}
};