1
class Solution {
2
public:
3
vector<int> partitionLabels(string s) {
4
unordered_map<char, int> mp;
5
// filling impact of character's
6
for (int i = 0; i < s.size(); i++) {
7
char ch = s[i];
8
mp[ch] = i;
9
}
10
// making of result
11
vector<int> res;
12
int prev = -1;
13
int maxi = 0;
14

15
for (int i = 0; i < s.size(); i++) {
16
maxi = max(maxi, mp[s[i]]);
17
if (maxi == i) {
18
// partition time
19
res.push_back(maxi - prev);
20
prev = maxi;
21
}
22
}
23
return res;
24
}
25
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0