easy中的easy,没啥说的
无脑把两个孩子丢进递归,加个对空值的处理,返回当前节点下最多的层数
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root==nullptr) return 0;
int res=1,l=0,r=0;
if(root->left!=NULL) l=maxDepth(root->left);
if(root->right!=NULL) r=maxDepth(root->right);
res+=max(l,r);
return res;
}
};