Skip to content

Commit 41e4ca0

Browse files
committed
Dec18
1 parent f490f71 commit 41e4ca0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Solutions <a href = "https://github.com/aliasvishnu/leetcode/tree/master/Solutio
8080
| 119 | BF | Generate new row from old row. | O(n^2) |
8181
| 128 | DP | DP problem, find recurrence relation. | |
8282
| 413 | Array | [1, 2, 3, 4, 5, 7, 9, 11]. can be written as [5, 3] i.e. 5 sequence of difference 1 and 3 sequence of difference 2, you need to figure out how many parts you can split 5 and 3 into. | O(n) |
83+
| 738 | Array | Find the first time Xi > Xi+1, Xi -= 1 and turn all Xi+k = 9, For eg, 321 becomes 299. However if there are repeating digits like 33332, then subtract the first occurrence then rest become 9, 33332 becomes 29999. | O(n) |
8384

8485
## Second hint list
8586

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
int monotoneIncreasingDigits(int N) {
4+
vector<int> n;
5+
6+
while(N != 0){
7+
n.push_back(N%10);
8+
N /= 10;
9+
}
10+
11+
reverse(n.begin(), n.end());
12+
13+
long answer = 0, len = n.size();
14+
for(int i = 0; i < len-1; i++){
15+
if(n[i] > n[i+1]){
16+
int j = i;
17+
while(n[j] == n[i]) j--;
18+
j++;
19+
n[j++] -= 1;
20+
21+
for(; j < len; j++) n[j] = 9;
22+
break;
23+
}
24+
}
25+
26+
for(int i = 0; i < len; i++) answer = answer*10+n[i];
27+
return answer;
28+
}
29+
};

0 commit comments

Comments
 (0)