We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4cec106 + 31ac198 commit b33e7b3Copy full SHA for b33e7b3
problems/0738.单调递增的数字.md
@@ -147,18 +147,15 @@ class Solution {
147
148
149
Python:
150
-```python
+```python3
151
class Solution:
152
def monotoneIncreasingDigits(self, n: int) -> int:
153
- strNum = list(str(n))
154
- flag = len(strNum)
155
- for i in range(len(strNum) - 1, 0, -1):
156
- if int(strNum[i]) < int(strNum[i - 1]):
157
- strNum[i - 1] = str(int(strNum[i - 1]) - 1)
158
- flag = i
159
- for i in range(flag, len(strNum)):
160
- strNum[i] = '9'
161
- return int("".join(strNum))
+ a = list(str(n))
+ for i in range(len(a)-1,0,-1):
+ if int(a[i]) < int(a[i-1]):
+ a[i-1] = str(int(a[i-1]) - 1)
+ a[i:] = '9' * (len(a) - i) #python不需要设置flag值,直接按长度给9就好了
+ return int("".join(a))
162
```
163
164
Go:
0 commit comments