Maximum 69 Number LeetCode solution in Python

1
class Solution:
2
def maximum69Number(self, num):
3
lst = list(str(num)) #! convert the number to a list
4
for i in range(len(lst)): #! iterate through the list
5
if lst[i] == "6": #! if the element is 6
6
lst[i] = "9" #! replace the element with 9
7
break #! break the loop
8
return int("".join(lst)) #! convert the list to a number

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0