Skip to content

Commit ecb4e68

Browse files
add 2583
1 parent 98e3511 commit ecb4e68

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11-
| 2582 |[Pass the Pillow](https://leetcode.com/problems/pass-the-pillow/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2582.java) | | Easy |
11+
| 2583 |[Kth Largest Sum in a Binary Tree](https://leetcode.com/problems/kth-largest-sum-in-a-binary-tree/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2583.java) | | Medium |
12+
| 2582 |[Pass the Pillow](https://leetcode.com/problems/pass-the-pillow/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2582.java) | | Easy |
1213
| 2566 |[Maximum Difference by Remapping a Digit](https://leetcode.com/problems/maximum-difference-by-remapping-a-digit/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2566.java) | | Easy |
1314
| 2562 |[Find the Array Concatenation Value](https://leetcode.com/problems/find-the-array-concatenation-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2562.java) | | Easy |
1415
| 2559 |[Count Vowel Strings in Ranges](https://leetcode.com/problems/count-vowel-strings-in-ranges/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2559.java) | | Medium |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder.solutions;
2+
3+
import com.fishercoder.common.classes.TreeNode;
4+
5+
import java.util.*;
6+
7+
public class _2583 {
8+
public static class Solution1 {
9+
public long kthLargestLevelSum(TreeNode root, int k) {
10+
List<Long> list = new ArrayList<>();
11+
Queue<TreeNode> queue = new LinkedList<>();
12+
queue.offer(root);
13+
while (!queue.isEmpty()) {
14+
int size = queue.size();
15+
long thisSum = 0l;
16+
for (int i = 0; i < size; i++) {
17+
TreeNode curr = queue.poll();
18+
thisSum += curr.val;
19+
if (curr.left != null) {
20+
queue.offer(curr.left);
21+
}
22+
if (curr.right != null) {
23+
queue.offer(curr.right);
24+
}
25+
}
26+
list.add(thisSum);
27+
}
28+
Collections.sort(list, Collections.reverseOrder());
29+
return k > list.size() ? -1 : list.get(k - 1);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)