Created
March 8, 2018 15:04
-
-
Save s4553711/af72b833f0c2d7df28e54f3e3db88da0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> partitionLabels(string S) { | |
vector<int> last_indx(128, 0); | |
for(int i = 0; i < S.size(); i++) | |
last_indx[S[i]] = i; | |
vector<int> ans; | |
int start = 0; | |
int end = 0; | |
for(int i = 0; i < S.size(); i++) { | |
// cout << "1> i: " << i << " ,end: " << end << endl; | |
end = max(end, last_indx[S[i]]); | |
// cout << "2> i: " << i << " ,end: " << end << endl; | |
if (i == end) { | |
ans.push_back(end - start + 1); | |
start = end + 1; | |
} | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment