Skip to content

Commit d4ba91a

Browse files
add 2974
1 parent c013f13 commit d4ba91a

File tree

2 files changed

+24
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src/main/java/com/fishercoder/solutions/thirdthousand

2 files changed

+24
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|---------------------------|----------------------------------------------------------------------
3+
| 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2974.java) | | Easy |
34
| 2970 | [Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2970.java) | | Easy |
45
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2965.java) | | Easy |
56
| 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2864.java) | | Easy |Greedy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.PriorityQueue;
4+
5+
public class _2974 {
6+
public static class Solution1 {
7+
public int[] numberGame(int[] nums) {
8+
PriorityQueue<Integer> minHeap = new PriorityQueue<>();
9+
for (int num : nums) {
10+
minHeap.offer(num);
11+
}
12+
int[] arr = new int[nums.length];
13+
int i = 0;
14+
while (!minHeap.isEmpty()) {
15+
int first = minHeap.poll();
16+
int second = minHeap.poll();
17+
arr[i++] = second;
18+
arr[i++] = first;
19+
}
20+
return arr;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)