Skip to content

Commit 9714d06

Browse files
add 3157
1 parent 66f111d commit 9714d06

File tree

2 files changed

+38
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions

2 files changed

+38
-0
lines changed

Diff for: paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
| 3174 | [Clear Digits](https://leetcode.com/problems/clear-digits/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_3174.java) | | Easy |
99
| 3164 | [Find the Number of Good Pairs II](https://leetcode.com/problems/find-the-number-of-good-pairs-ii/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_3164.java) | | Medium |
1010
| 3162 | [Find the Number of Good Pairs I](https://leetcode.com/problems/find-the-number-of-good-pairs-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_3162.java) | | Easy |
11+
| 3157 | [Find the Level of Tree with Minimum Sum](https://leetcode.com/problems/find-the-level-of-tree-with-minimum-sum/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_3157.java) | | Medium |BFS
1112
| 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_3131.java) | | Easy |
1213
| 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_3127.java) | | Easy |
1314
| 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/_3120.java) | | Easy |

Diff for: src/main/java/com/fishercoder/solutions/_3157.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fishercoder.solutions;
2+
3+
import com.fishercoder.common.classes.TreeNode;
4+
5+
import java.util.LinkedList;
6+
import java.util.Queue;
7+
import java.util.TreeMap;
8+
9+
public class _3157 {
10+
public static class Solution1 {
11+
public int minimumLevel(TreeNode root) {
12+
Queue<TreeNode> q = new LinkedList<>();
13+
q.offer(root);
14+
TreeMap<Long, Integer> treeMap = new TreeMap<>();
15+
int level = 1;
16+
while (!q.isEmpty()) {
17+
int size = q.size();
18+
long sum = 0L;
19+
for (int i = 0; i < size; i++) {
20+
TreeNode curr = q.poll();
21+
sum += curr.val;
22+
if (curr.left != null) {
23+
q.offer(curr.left);
24+
}
25+
if (curr.right != null) {
26+
q.offer(curr.right);
27+
}
28+
}
29+
if (!treeMap.containsKey(sum)) {
30+
treeMap.put(sum, level);
31+
}
32+
level++;
33+
}
34+
return treeMap.firstEntry().getValue();
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)