ほぼ日刊競プロ leetcode 1323. Maximum 69 Number
1323. Maximum 69 Number
You are given a positive integer num consisting only of digits 6 and 9.
Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).
考えたこと
与えられた整数の大きい位の数から1度だけ6を9に変換してあげれば良い.
なかったらそのままで
class Solution:
def maximum69Number (self, num: int) -> int:
temp = num
x = [str(a) for a in str(num)]
for i in range(len(x)):
if x[i]=="6":
x[i]="9"
break
return max(temp,int("".join(x)))