File tree Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Expand file tree Collapse file tree 2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 13
13
14
14
## 🎯 Calendar
15
15
16
-
17
- * 2023/12
16
+ * 2024/1
18
17
19
18
| Mon| Tue| Wed| Thu| Fri| Sat| Sun|
20
19
| :-:| :-:| :-:| :-:| :-:| :-:| :-:|
21
- | 27 | 28 | 29 | 30 | 1 | 2 | 3 |
22
- | 4 | 5 | 6 | 7 | 8 | 9 | 10🌟 |
23
- | 11 | 12 | 13 | 14 | 15 | 16🌟 | 17 |
24
- | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25
- | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
20
+ | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
21
+ | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
22
+ | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
23
+ | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
24
+ | 29 | 30 | 31 | 1🌟 | 2 | 3 | 4 |
26
25
27
26
28
27
## 🍃 Records
29
28
30
29
| #| Title| Tag| Date|
31
30
| :-:| :-:| :-:| :-:|
31
+ | 11| [ 543. 二叉树的直径] ( https://github.com/Doragd/Algorithm/issues/11 ) | ` 二叉树 ` | 2024-01-01T09:05:12Z|
32
32
| 6| [ 101. 对称二叉树] ( https://github.com/Doragd/Algorithm/issues/6 ) | ` 二叉树 ` ` 递归 ` | 2023-12-16T02:01:21Z|
33
33
| 3| [ 100. 相同的树] ( https://github.com/Doragd/Algorithm/issues/3 ) | ` 二叉树 ` ` 递归 ` | 2023-12-10T12:14:09Z|
34
34
| 2| [ 110. 平衡二叉树] ( https://github.com/Doragd/Algorithm/issues/2 ) | ` 二叉树 ` ` 递归 ` | 2023-12-10T10:56:53Z|
Original file line number Diff line number Diff line change
1
+ # 543. 二叉树的直径
2
+
3
+ [ 543. 二叉树的直径] ( https://leetcode.cn/problems/diameter-of-binary-tree/ )
4
+ - 给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。** 注意:** 两结点之间的路径长度是以它们之间边的数目表示。
5
+ ``` C++
6
+ class Solution {
7
+ public:
8
+ int res = INT_MIN;
9
+ int dfs(TreeNode * root){
10
+ if(!root) return 0;
11
+ int left_val = dfs(root->left);
12
+ int right_val = dfs(root->right);
13
+ int cur = left_val + right_val; //以当前结点为最高点的路径长度: 边的数目
14
+ res = max(res, cur); //最大值
15
+ return max(left_val, right_val) + 1; //单边的最大路径和: 点的数目
16
+ }
17
+ int diameterOfBinaryTree(TreeNode* root) {
18
+ dfs(root);
19
+ return res;
20
+ }
21
+ };
22
+ ```
23
+
24
+ ---
25
+
26
+ * Link: https://github.com/Doragd/Algorithm/issues/11
27
+ * Labels: `二叉树`
28
+ * Creation Date: 2024-01-01T09:05:12Z
You can’t perform that action at this time.
0 commit comments