深度优先搜索
int maxDepth(TreeNode* root) {
if (root == NULL) {
return 0;
}
int lheight = 0, rheight = 0;
if (root->left != NULL) {
lheight = maxDepth(root->left);
}
if (root->right != NULL) {
rheight = maxDepth(root->right);
}
return max(lheight, rheight) + 1;
}
其实可以简化成一行