Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d3ae53e

Browse files
Merge pull request youngyangyang04#2813 from lllyt8/master
Update 0738.单调递增的数字.md
2 parents 618419a + dfe65d9 commit d3ae53e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

‎problems/0738.单调递增的数字.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ class Solution:
190190
贪心(版本一)
191191
```python
192192
class Solution:
193-
def monotoneIncreasingDigits(self, N: int) -> int:
193+
def monotoneIncreasingDigits(self, n: int) -> int:
194194
# 将整数转换为字符串
195-
strNum = str(N)
195+
strNum = str(n)
196196
# flag用来标记赋值9从哪里开始
197197
# 设置为字符串长度,为了防止第二个for循环在flag没有被赋值的情况下执行
198198
flag = len(strNum)
@@ -216,9 +216,9 @@ class Solution:
216216
贪心(版本二)
217217
```python
218218
class Solution:
219-
def monotoneIncreasingDigits(self, N: int) -> int:
219+
def monotoneIncreasingDigits(self, n: int) -> int:
220220
# 将整数转换为字符串
221-
strNum = list(str(N))
221+
strNum = list(str(n))
222222

223223
# 从右往左遍历字符串
224224
for i in range(len(strNum) - 1, 0, -1):
@@ -238,9 +238,9 @@ class Solution:
238238

239239
```python
240240
class Solution:
241-
def monotoneIncreasingDigits(self, N: int) -> int:
241+
def monotoneIncreasingDigits(self, n: int) -> int:
242242
# 将整数转换为字符串
243-
strNum = list(str(N))
243+
strNum = list(str(n))
244244

245245
# 从右往左遍历字符串
246246
for i in range(len(strNum) - 1, 0, -1):
@@ -258,8 +258,8 @@ class Solution:
258258

259259
```python
260260
class Solution:
261-
def monotoneIncreasingDigits(self, N: int) -> int:
262-
strNum = str(N)
261+
def monotoneIncreasingDigits(self, n: int) -> int:
262+
strNum = str(n)
263263
for i in range(len(strNum) - 1, 0, -1):
264264
# 如果当前字符比前一个字符小,说明需要修改前一个字符
265265
if strNum[i - 1] > strNum[i]:
@@ -272,12 +272,12 @@ class Solution:
272272
```
273273
### Go
274274
```go
275-
func monotoneIncreasingDigits(N int) int {
275+
func monotoneIncreasingDigits(n int) int {
276276
s := strconv.Itoa(N)//将数字转为字符串,方便使用下标
277277
ss := []byte(s)//将字符串转为byte数组,方便更改。
278278
n := len(ss)
279279
if n <= 1 {
280-
return N
280+
return n
281281
}
282282
for i := n-1; i > 0; i-- {
283283
if ss[i-1] > ss[i] { //前一个大于后一位,前一位减1,后面的全部置为9

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /