leetcode 102
我模仿二叉树的层序遍历的方法,自己写了一个。中间报错了,还特别去看了下这个文章https://blog.csdn.net/weixin_45799835/article/details/105780627
后来发现只是一个小错误,嘻嘻
class Solution {
public:
int maxDepth(TreeNode* root) {
int dep=0;
exp(root,1,dep);
return dep;
}
void exp(TreeNode*root,int c,int &dep)
{
if(!root) return;
if(c>dep)
++dep;
exp(root->left,c+1,dep);
exp(root->right,c+1,dep);
}
};
END