Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- private:
- const int MAX = 26;
- public:
- vector<int> partitionLabels(string s) {
- int last[MAX];
- for (int i = 0; i < (int) s.size(); i++)
- last[s[i] - 'a'] = i;
- int idx = 0;
- vector<int> ans;
- while (idx < (int) s.size()) {
- int size = 1, aux = idx;
- while (aux < (int) s.size() && aux < idx + size) {
- size = max(size, last[s[aux++] - 'a'] - idx + 1);
- }
- idx += size;
- ans.push_back(size);
- }
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment