题目:
题解:
typedef struct TreeNode Node;
int method (Node* root, int* max) {
if (root == NULL)
return 0;
int left = method (root->left, max);
int right = method (root->right, max);
*max = *max > (left + right) ? *max : (left + right);
return (left > right ? left : right) + 1;
}
int diameterOfBinaryTree(struct TreeNode* root) {
int max = 0;
method (root, &max);
return max;
}