Skip to content

Commit b71e7e4

Browse files
solves #2293: Min Max Game in java
1 parent 42be577 commit b71e7e4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@
739739
| 2278 | [Percentage of Letter in String](https://leetcode.com/problems/percentage-of-letter-in-string) | [![Java](assets/java.png)](src/PercentageOfLetterInString.java) | |
740740
| 2283 | [Check if Number Has Equal Digit Count and Digit Value](https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value) | [![Java](assets/java.png)](src/CheckIfNumberHasEqualDigitCountAndDigitValue.java) | |
741741
| 2287 | [Rearrange Characters to Make Target String](https://leetcode.com/problems/rearrange-characters-to-make-target-string) | [![Java](assets/java.png)](src/RearrangeCharactersToMakeTargetString.java) | |
742-
| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | | |
742+
| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | |
743743
| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | | |
744744
| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | |
745745
| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | |

Diff for: src/MinMaxGame.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// https://leetcode.com/problems/min-max-game
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class MinMaxGame {
6+
public int minMaxGame(int[] array) {
7+
for (int len = array.length / 2 ; len > 1 ; len /= 2) {
8+
for (int i = 0 ; i < len ; i++) {
9+
array[i] = i % 2 == 0 ? Math.min(array[2 * i], array[2 * i + 1]) : Math.max(array[2 * i], array[2 * i + 1]);
10+
}
11+
}
12+
return array[0];
13+
}
14+
}

0 commit comments

Comments
 (0)