Skip to content

Commit 127a55c

Browse files
committed
update new record
1 parent 306ffd7 commit 127a55c

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313

1414
## 🎯 Calendar
1515

16-
17-
* 2023/12
16+
* 2024/1
1817

1918
|Mon|Tue|Wed|Thu|Fri|Sat|Sun|
2019
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
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|
2625

2726

2827
## 🍃 Records
2928

3029
|#|Title|Tag|Date|
3130
|:-:|:-:|:-:|:-:|
31+
|11|[543. 二叉树的直径](https://github.com/Doragd/Algorithm/issues/11)|`二叉树`|2024-01-01T09:05:12Z|
3232
|6|[101. 对称二叉树](https://github.com/Doragd/Algorithm/issues/6)|`二叉树` `递归`|2023-12-16T02:01:21Z|
3333
|3|[100. 相同的树](https://github.com/Doragd/Algorithm/issues/3)|`二叉树` `递归`|2023-12-10T12:14:09Z|
3434
|2|[110. 平衡二叉树](https://github.com/Doragd/Algorithm/issues/2)|`二叉树` `递归`|2023-12-10T10:56:53Z|

backup/11#543. 二叉树的直径.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

0 commit comments

Comments
 (0)