Skip to content

Commit 8975473

Browse files
add 1323
1 parent ac0266b commit 8975473

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ _If you like this project, please leave me a star._ ★
1111
|1333|[Filter Restaurants by Vegan-Friendly, Price and Distance](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1333.java) | |Medium||
1212
|1331|[Rank Transform of an Array](https://leetcode.com/problems/rank-transform-of-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1331.java) | |Easy||
1313
|1329|[Sort the Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1329.java) | |Medium||
14+
|1323|[Maximum 69 Number](https://leetcode.com/problems/maximum-69-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1323.java) | |Easy|Math|
1415
|1317|[Convert Integer to the Sum of Two No-Zero Integers](https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1317.java) | |Easy||
1516
|1313|[Decompress Run-Length Encoded List](https://leetcode.com/problems/decompress-run-length-encoded-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1313.java) | |Easy|Array|
1617
|1305|[All Elements in Two Binary Search Trees](https://leetcode.com/problems/all-elements-in-two-binary-search-trees/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1305.java) | |Medium||
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.stream.IntStream;
4+
5+
/**
6+
* 1323. Maximum 69 Number
7+
*
8+
* Given a positive integer num consisting only of digits 6 and 9.
9+
* Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).
10+
*
11+
* Example 1:
12+
* Input: num = 9669
13+
* Output: 9969
14+
* Explanation:
15+
* Changing the first digit results in 6669.
16+
* Changing the second digit results in 9969.
17+
* Changing the third digit results in 9699.
18+
* Changing the fourth digit results in 9666.
19+
* The maximum number is 9969.
20+
*
21+
* Example 2:
22+
* Input: num = 9996
23+
* Output: 9999
24+
* Explanation: Changing the last digit 6 to 9 results in the maximum number.
25+
*
26+
* Example 3:
27+
* Input: num = 9999
28+
* Output: 9999
29+
* Explanation: It is better not to apply any change.
30+
*
31+
* Constraints:
32+
* 1 <= num <= 10^4
33+
* num's digits are 6 or 9.
34+
* */
35+
public class _1323 {
36+
public static class Solution1 {
37+
public int maximum69Number (int num) {
38+
char[] chars = Integer.toString(num).toCharArray();
39+
IntStream.range(0, chars.length).filter(i -> chars[i] == '6').findFirst().ifPresent(i -> chars[i] = '9');
40+
return Integer.parseInt(new String(chars));
41+
}
42+
}
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1323;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1323Test {
10+
private static _1323.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1323.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(9969, solution1.maximum69Number(9669));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)