class Solution {
public:
static bool cmp(const vector<int>& a, const vector<int>& b){
return a[0] < b[0];
}
int findMinArrowShots(vector<vector<int>>& points) {
if(points.size() == 0) return 0;
sort(points.begin(), points.end(), cmp);
int result = 1;
for(int i = 1; i < points.size(); i++){
if(points[i][0] > points[i - 1][1]) result++;
else{
points[i][1] = min(points[i][1], points[i - 1][1]);
}
}
return result;
}
};
435.无重叠区间
class Solution {
public:
static bool cmp(const vector<int>& a, const vector<int>& b){
return a[1] < b[1];
}
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
if(intervals.size() == 1) return 0;
int count = 1;
sort(intervals.begin(), intervals.end(), cmp);
int tmp = intervals[0][1];
for(int i = 1; i < intervals.size(); i++){
if(intervals[i][0] >= tmp){
count++;
tmp = intervals[i][1];
}
}
return intervals.size() - count;
}
};
763.划分字母区间
class Solution {
public:
vector<int> partitionLabels(string s) {
int hash[26] = {0};
for(int i = 0; i < s.size(); i++){
hash[s[i] - 'a'] = i;
}
int right = 0;
int left = 0;
vector<int> result;
for(int i = 0; i < s.size(); i++){
right = max(hash[s[i] - 'a'], right);
if(i == right){
result.push_back(right - left + 1);
left = i + 1;
}
}
return result;
}
};