forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0763.cpp
More file actions
33 lines (24 loc) · 699 Bytes
/
0763.cpp
File metadata and controls
33 lines (24 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
vector<int> partitionLabels(string s) {
unordered_map<char,int> map1;
for(auto c : s)
map1[c]++;
unordered_map<char,int> map2;
int temp = 0;
vector<int> result;
for(int i = 0; i < s.size(); i++){
char ch = s[i];
temp++;
map2[ch] = 1;
map1[ch]--;
if(map1[ch] == 0)
map2.erase(ch);
if(map2.size() == 0){
result.push_back(temp);
temp = 0;
}
}
return result;
}
};