We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 89351e1 commit f89ceffCopy full SHA for f89ceff
763. Partition Labels
@@ -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