Problem:
My code:
class Solution {
public:
vector<int> partitionLabels(string s) {
map<char,int> m; //last index of each character in s
vector<int> ans;
for(int i=0;i<s.length();i++){
m[s[i]]=i;
}
int i=0;
while(i<s.length()){
char current=s[i];
int last_index=m[current];
int j=i;
while(j<=last_index){
last_index=max(last_index,m[s[j]]);
j++;
}
ans.push_back(j-i);
i=j;
}
return ans;
}
};
Whats the time complexity is it O(n)?