File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy
2
+
3
+ import GreedyTopic
4
+ import MathTopic
5
+
6
+ /* *
7
+ * 1323. Maximum 69 Number
8
+ * https://leetcode.com/problems/maximum-69-number/
9
+ *
10
+ You are given a positive integer num consisting only of digits 6 and 9.
11
+ Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).
12
+ */
13
+
14
+ class Easy1323 : MathTopic , GreedyTopic {
15
+
16
+ fun maximum69Number (num : Int ): Int {
17
+ val arr = num.toString().toCharArray()
18
+ for (i in arr.indices) {
19
+ if (arr[i] == ' 6' ) {
20
+ arr[i] = ' 9'
21
+ return String (arr).toInt()
22
+ }
23
+ }
24
+ return num
25
+ }
26
+ }
27
+
28
+ fun main () {
29
+ println (Easy1323 ().maximum69Number(9669 ))
30
+ println (Easy1323 ().maximum69Number(9996 ))
31
+ println (Easy1323 ().maximum69Number(9999 ))
32
+ }
You can’t perform that action at this time.
0 commit comments