Skip to content

Commit 645c6e7

Browse files
committed
Time: 0 ms (100.00%), Space: 5.9 MB (76.22%) - LeetHub
1 parent a74933e commit 645c6e7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int monotoneIncreasingDigits(int N) {
4+
string str = to_string(N);
5+
int n = str.size();
6+
7+
int idx = n - 1;
8+
9+
for(int i = n - 1; i > 0; i--){
10+
if(str[i - 1] > str[i]){
11+
str[i - 1]--;
12+
idx = i - 1;
13+
}
14+
}
15+
16+
17+
for(int i = idx + 1; i < n; i++){
18+
str[i] = '9';
19+
}
20+
21+
return stoi(str);
22+
}
23+
};

0 commit comments

Comments
 (0)