版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zem_nezer/article/details/86678016
int dfs(root): the max. length of one of substree.
i.e.
dfs(root):
if(root == null)
return 0
left += dfs(root->left)
right += dfs(root->right)
res = max(res, left + right + 1);
return max(left, right) + 1;
Error:
- calculate the path not the node, so we need to -1 at the end.