Skip to content

Commit 7095cdd

Browse files
refactor 543
1 parent d2b3c80 commit 7095cdd

File tree

1 file changed

+3
-20
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-20
lines changed

src/main/java/com/fishercoder/solutions/_543.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,11 @@
22

33
import com.fishercoder.common.classes.TreeNode;
44

5-
/**
6-
* 543. Diameter of Binary Tree
7-
*
8-
* Given a binary tree, you need to compute the length of the diameter of the tree.
9-
* The diameter of a binary tree is the length of the longest path between any two nodes in a tree.
10-
* This path may or may not pass through the root.
11-
12-
Example:
13-
Given a binary tree
14-
1
15-
/ \
16-
2 3
17-
/ \
18-
4 5
19-
Return 3, which is the length of the path [4,2,1,3] or [5,2,1,3].
20-
21-
Note: The length of path between two nodes is represented by the number of edges between them.
22-
*/
235
public class _543 {
246

257
public static class Solution1 {
26-
/**This is a very great problem for practicing recursion:
8+
/**
9+
* This is a very great problem for practicing recursion:
2710
* 1. What dfs() returns is the max height it should pick from either its left or right subtree, that's
2811
* what the int return type stands for;
2912
* 2. And during the recursion, we can keep updating the global variable: "diameter";
@@ -32,7 +15,7 @@ public static class Solution1 {
3215
* int left = dfs(root.left);
3316
* instead of dfs(root.left) + 1;
3417
* we'll only plus one at the end
35-
* */
18+
*/
3619
int diameter = 0;
3720

3821
public int diameterOfBinaryTree(TreeNode root) {

0 commit comments

Comments
 (0)