mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
Update 0738.单调递增的数字.md
0738.单调递增的数字增加C语言实现
This commit is contained in:
@ -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>
|
||||
|
||||
|
Reference in New Issue
Block a user