Update 0738.单调递增的数字,添加C#

This commit is contained in:
eeee0717
2024-01-09 10:47:42 +08:00
parent 98827c14d0
commit 6b38053a63

View File

@ -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));
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">