文章作者:Tyan 博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
**解析:**Version 1,从左到右,找到第一个6
,将其改为9
,返回更改之后的数字。
- Version 1
class Solution:
def maximum69Number (self, num: int) -> int:
digits = list(str(num))
for index, digit in enumerate(digits):
if digit == '6':
digits[index] = '9'
break
return int(''.join(digits))
**解析:**Version 2。
- Version 2
class Solution:
def maximum69Number (self, num: int) -> int:
return int(str(num).replace('6', '9', 1))
Reference
- https://leetcode.com/problems/maximum-69-number/