版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/83859099
https://leetcode.com/problems/monotone-increasing-digits/description/
class Solution {
public:
int monotoneIncreasingDigits(int N) {
string str = to_string(N);
int n = str.size(), j = n;
for(int i=n-1; i>0; i--){
if(str[i]>=str[i-1]) continue;
--str[i-1];
j = i;
}
for(int i=j; i<n; i++){
str[i] = '9';
}
return stoi(str);
}
};