We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
543. 二叉树的直径
class Solution { public: int res = INT_MIN; int dfs(TreeNode *root){ if(!root) return 0; int left_val = dfs(root->left); int right_val = dfs(root->right); int cur = left_val + right_val; //以当前结点为最高点的路径长度: 边的数目 res = max(res, cur); //最大值 return max(left_val, right_val) + 1; //单边的最大路径和: 点的数目 } int diameterOfBinaryTree(TreeNode* root) { dfs(root); return res; } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
543. 二叉树的直径
The text was updated successfully, but these errors were encountered: