Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15ae5e9

Browse files
committed
提交543,删除110
1 parent 721187f commit 15ae5e9

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

‎leetcode/src/main/java/com/mistray/tree/BalancedBinaryTree110.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,4 @@ public static void main(String[] args) {
1313

1414
}
1515

16-
int max = 0;
17-
18-
public int diameterOfBinaryTree(TreeNode root) {
19-
if (root == null) {
20-
return 0;
21-
}
22-
max(root);
23-
return max;
24-
}
25-
26-
public int max(TreeNode root) {
27-
if (root == null) {
28-
return 0;
29-
}
30-
int L = max(root.left);
31-
int R = max(root.right);
32-
max = Math.max(max, L + R);
33-
// 返回的是当前节点子树的最大深度,左节点和右节点对比后得到较大值后再加一.
34-
// 加一的原因是,需要算当前树高.
35-
return Math.max(L, R) + 1;
36-
}
3716
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.mistray.tree;
2+
3+
/**
4+
* @author ZJY(MistRay)
5+
* @Project algorithm-study
6+
* @Package com.mistray.tree
7+
* @create 2020年03月06日 17:58
8+
* @Desc
9+
*/
10+
public class DiameterOfBinaryTree543 {
11+
12+
int max = 0;
13+
14+
public int diameterOfBinaryTree(TreeNode root) {
15+
if (root == null) {
16+
return 0;
17+
}
18+
max(root);
19+
return max;
20+
}
21+
22+
public int max(TreeNode root) {
23+
if (root == null) {
24+
return 0;
25+
}
26+
int L = max(root.left);
27+
int R = max(root.right);
28+
max = Math.max(max, L + R);
29+
// 返回的是当前节点子树的最大深度,左节点和右节点对比后得到较大值后再加一.
30+
// 加一的原因是,需要算当前树高.
31+
return Math.max(L, R) + 1;
32+
}
33+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /