Skip to content

Commit ea1fbdc

Browse files
solve #2974: Minimum Number Game in java
1 parent 887f07f commit ea1fbdc

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@
877877
| 2960 | [Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) | [![Java](assets/java.png)](src/CountTestedDevicesAfterTestOperations.java) | |
878878
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values) | [![Java](assets/java.png)](src/FindMissingAndRepeatedValues.java) | |
879879
| 2970 | [Count the Number of Irremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) | [![Java](assets/java.png)](src/CountTheNumberOfIncremovableSubarraysI.java) | |
880-
| 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | | |
880+
| 2974 | [Minimum Number Game](https://leetcode.com/problems/minimum-number-game) | [![Java](assets/java.png)](src/MinimumNumberGame.java) | |
881881
| 2980 | [Check if Bitwise OR Has Trailing Zeros](https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros) | | |
882882
| 2996 | [Smallest Missing Integer Greater Than Sequential Prefix Sum](https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum) | | |
883883
| 3000 | [Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle) | | |

src/MinimumNumberGame.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://leetcode.com/problems/minimum-number-game
2+
// T: O(N*log(N))
3+
// S: O(log(N))
4+
5+
import java.util.Arrays;
6+
7+
public class MinimumNumberGame {
8+
public int[] numberGame(int[] array) {
9+
Arrays.sort(array);
10+
final int[] result = new int[array.length];
11+
12+
for (int i = 0 ; i < array.length ; i += 2) {
13+
result[i] = array[i + 1];
14+
result[i + 1] = array[i];
15+
}
16+
17+
return result;
18+
}
19+
}

0 commit comments

Comments
 (0)