二叉树的深度
class Solution {
public:
int treeDepth(TreeNode* root) {
if(!root) return 0;
return max(treeDepth(root->left),treeDepth(root->right))+1;
}
};
有帮助的话可以点个赞,我会很开心的~
class Solution {
public:
int treeDepth(TreeNode* root) {
if(!root) return 0;
return max(treeDepth(root->left),treeDepth(root->right))+1;
}
};