//节点结构体
struct BinaryTreeNode
{
BinaryTreeNode* left = NULL;
BinaryTreeNode* right = NULL;
int floor = 1;
};
//查找最大路径,返回路径长度
int FindMaxPath(BinaryTreeNode* t)
{
if (t)
{
int lpath = FindMaxPath(t->left);//左子树最大路径
int rpath = FindMaxPath(t->right);//右子树最大路径
//t做根的树的层数等于子树最大层数+1
t->floor = max2((t->left) ? t->left->floor : 0, (t->right) ? t->right->floor : 0) + 1;
//结论1
return max3(lpath, rpath, ((t->left) ? t->left->floor : 0) + ((t->right) ? t->right->floor : 0) );
}
return 0;
}