Skip to content

Commit 0c37eab

Browse files
refactor 687
1 parent d724ebe commit 0c37eab

File tree

1 file changed

+1
-34
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+1
-34
lines changed

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

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,6 @@
22

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

5-
/**
6-
* 687. Longest Univalue Path
7-
*
8-
* Given a binary tree, find the length of the longest path where each node in the path has the same value.
9-
* This path may or may not pass through the root.
10-
11-
Note: The length of path between two nodes is represented by the number of edges between them.
12-
13-
Example 1:
14-
Input:
15-
5
16-
/ \
17-
4 5
18-
/ \ \
19-
1 1 5
20-
21-
Output:
22-
2
23-
24-
Example 2:
25-
Input:
26-
27-
1
28-
/ \
29-
4 5
30-
/ \ \
31-
4 4 5
32-
Output:
33-
2
34-
35-
Note: The given binary tree has not more than 10000 nodes. The height of the tree is not more than 1000.
36-
*/
37-
385
public class _687 {
396
public static class Solution1 {
407
/**
@@ -47,7 +14,7 @@ public int longestUnivaluePath(TreeNode root) {
4714
}
4815
return result[0];
4916
}
50-
17+
5118
// calculate longest univalue path from root to leaves
5219
// In addition, the maximum univalue path cross the root node is calculated and then global maximum is udpated.
5320
private int dfs(TreeNode root, int[] result) {

0 commit comments

Comments
 (0)