二叉树的深度最小的
程序员文章站
2022-07-14 18:07:33
...
class Solution {
public:
int run(TreeNode *root) {
if (root == NULL){
return 0;
}
if (root->left == NULL){
return run(root->right) + 1;
}
if (root->right == NULL){
return run(root->left) + 1;
}
int l = run(root->left);
int r = run(root->right);
return l > r ? (r + 1) : (l + 1);
}
};