Update 0738.单调递增的数字.md

0738.单调递增的数字增加C语言实现
This commit is contained in:
a12bb
2024-02-29 20:55:06 +08:00
parent 48e65c1de9
commit 64399ddf6f

View File

@ -392,7 +392,33 @@ impl Solution {
}
}
```
### C
```c
int monotoneIncreasingDigits(int n) {
char str[11];
// 将数字转换为字符串
sprintf(str, "%d", n);
int len = strlen(str);
int flag = strlen(str);
for(int i = len - 1; i > 0; i--){
if(str[i] < str[i - 1]){
str[i - 1]--;
flag = i;
}
}
for(int i = flag; i < len; i++){
str[i] = '9';
}
// 字符串转数字
return atoi(str);
}
```
### C#
```csharp
public class Solution
{
@ -421,4 +447,3 @@ public class Solution
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>