Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aded8e1

Browse files
author
konstantin
committed
Easy1323 challenge
1 parent 32716d6 commit aded8e1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎src/easy/1323. Maximum 69 Number .kt‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /