diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md index 400dc90d..4a8a6e08 100644 --- a/problems/0738.单调递增的数字.md +++ b/problems/0738.单调递增的数字.md @@ -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 -