Skip to content

Commit f89ceff

Browse files
authored
Create 763. Partition Labels
1 parent 89351e1 commit f89ceff

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

763. Partition Labels

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
vector<int> partitionLabels(string s) {
4+
vector<int> ans;
5+
vector<int> last(26, 0);
6+
for (int i = 0; i < s.size(); i++) {
7+
last[s[i] - 'a'] = i;
8+
}
9+
set<char> st;
10+
int partitionStart = 0;
11+
for(int i=0;i<s.size();i++){
12+
st.insert(s[i]);
13+
if(i==last[s[i]-'a']){
14+
st.erase(s[i]);
15+
}
16+
if(st.empty()){
17+
ans.push_back(i-partitionStart+1);
18+
partitionStart=i+1;
19+
}
20+
}
21+
return ans;
22+
}
23+
};

0 commit comments

Comments
 (0)