class Solution {
public:
//使用前序求的就是深度,使用后序求的是高度。而根节点的高度就是二叉树的最大深度,所以本题中我们通过后序求的根节点高度来求的二叉树最大深度。
int getdepth(TreeNode* node){
if (node == NULL) return 0;//终止条件
int ldepth = 1 + getdepth(node->left);//左
int rdepth = 1 + getdepth(node->right);//右
int depth = max(ldepth,rdepth);//中
return depth;
}
int maxDepth(TreeNode* root) {
int depth = getdepth(root);
return depth;
}
};



