1 class Solution:
 2     def maximum69Number (self, num: int) -> int:
 3         result = ''
 4         str_num = str(num)
 5         i = 0
 6         while i < len(str_num):
 7             if str_num[i] == '6':
 8                 result += '9'
 9                 result += str_num[i+1:]
10                 return result
11             else:
12                 result += str_num[i]
13             i += 1
14         return result

遍历数字,将第一个6变成9,然后返回。