From 6b38053a63c0a1896ac6ec7905fc17a0a770f91b Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Tue, 9 Jan 2024 10:47:42 +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=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0738.单调递增的数字.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md index c2215cf6..400dc90d 100644 --- a/problems/0738.单调递增的数字.md +++ b/problems/0738.单调递增的数字.md @@ -392,6 +392,30 @@ impl Solution { } } ``` +### C# +```csharp +public class Solution +{ + public int MonotoneIncreasingDigits(int n) + { + char[] s = n.ToString().ToCharArray(); + int flag = s.Length; + for (int i = s.Length - 1; i > 0; i--) + { + if (s[i - 1] > s[i]) + { + flag = i; + s[i - 1]--; + } + } + for (int i = flag; i < s.Length; i++) + { + s[i] = '9'; + } + return int.Parse(new string(s)); + } +} +```