Skip to content

Commit 7b12e00

Browse files
committed
Runtime: 14 ms (Top 14.50%) | Memory: 44.9 MB (Top 83.15%)
1 parent ac8b1b2 commit 7b12e00

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
// Runtime: 14 ms (Top 14.50%) | Memory: 44.9 MB (Top 83.15%)
12
class Solution {
23
public int[] findFrequentTreeSum(TreeNode root) {
3-
4+
45
HashMap<Integer,Integer> map=new HashMap<>();
56
int sum=sum(root,map);
67
int max=0;
78
int count=0;
89
for(Integer key:map.keySet()){
910
max=Math.max(max,map.get(key));
1011
}
11-
12+
1213
for(Integer key:map.keySet()){
1314
if(max==map.get(key)){
1415
count++;
@@ -21,11 +22,9 @@ public int[] findFrequentTreeSum(TreeNode root) {
2122
ans[counter++]=key;
2223
}
2324
}
24-
25-
26-
25+
2726
return ans;
28-
27+
2928
}
3029
public int sum(TreeNode root,HashMap<Integer,Integer> map){
3130
if(root==null)return 0;
@@ -34,4 +33,4 @@ public int sum(TreeNode root,HashMap<Integer,Integer> map){
3433
map.put(lh+rh+root.val,map.getOrDefault(lh+rh+root.val,0)+1);
3534
return lh+rh+root.val;
3635
}
37-
}
36+
}

0 commit comments

Comments
 (0)