From f30fc5649df4a450406c65811d0979c9011d99fd Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Sat, 17 Dec 2022 16:02:03 +0800 Subject: [PATCH] =?UTF-8?q?update=200738.=E5=8D=95=E8=B0=83=E9=80=92?= =?UTF-8?q?=E5=A2=9E=E7=9A=84=E6=95=B0=E5=AD=97:=20=E4=BF=AE=E6=94=B9=20go?= =?UTF-8?q?=20=E4=BB=A3=E7=A0=81=E5=A4=84markdown=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0738.单调递增的数字.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md index 89630827..e8666bcd 100644 --- a/problems/0738.单调递增的数字.md +++ b/problems/0738.单调递增的数字.md @@ -179,7 +179,7 @@ class Solution: ``` ### Go -```golang +```go func monotoneIncreasingDigits(N int) int { s := strconv.Itoa(N)//将数字转为字符串,方便使用下标 ss := []byte(s)//将字符串转为byte数组,方便更改。 @@ -187,10 +187,10 @@ func monotoneIncreasingDigits(N int) int { if n <= 1 { return N } - for i:=n-1 ; i>0; i-- { - if ss[i-1] > ss[i] {//前一个大于后一位,前一位减1,后面的全部置为9 + for i := n-1; i > 0; i-- { + if ss[i-1] > ss[i] { //前一个大于后一位,前一位减1,后面的全部置为9 ss[i-1] -= 1 - for j := i ; j < n; j++ {//后面的全部置为9 + for j := i; j < n; j++ { //后面的全部置为9 ss[j] = '9' } }