class Solution {
public:
static bool cmp(vector<int>& A,vector<int>& B)
{
return A[1]<B[1];
}
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
if(intervals.size()==0) return 0;
sort(intervals.begin(),intervals.end(),cmp);
int end=intervals[0][1];
int count=1;
for(int i=1;i<intervals.size();i++)
{
if(end<=intervals[i][0])
{
end=intervals[i][1];
count++;
}
}
return intervals.size()-count;
}
};
class Solution {
public:
vector<int> partitionLabels(string s) {
int hash[27]={0};
for(int i=0;i<s.size();i++)
{
hash[s[i]-'a']=i;
}
vector<int> result;
int left=0;
int right=0;
for(int i=0;i<s.size();i++)
{
right=max(right,hash[s[i]-'a']);
if(right==i)
{
result.push_back(right-left+1);
left=i+1;
}
}
return result;
}
};
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals) {
vector<vector<int>> result;
sort(intervals.begin(),intervals.end(),[](vector<int>&a,vector<int>&b){return a[0]<b[0];});
result.push_back(intervals[0]);
for(int i=1;i<intervals.size();i++)
{
if(result.back()[1]>=intervals[i][0])
{
result.back()[1]=max(result.back()[1],intervals[i][1]);
}
else
result.push_back(intervals[i]);
}
return result;
}
};