mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Update 0738.单调递增的数字,添加C#
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user