leetcode-543-Diameter of Binary Tree

版权声明:本文为博主原创文章,未经博主允许不得转载。 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:

  1. calculate the path not the node, so we need to -1 at the end.

猜你喜欢

转载自blog.csdn.net/zem_nezer/article/details/86678016
今日推荐