452.用最少数量的箭引爆气球
class Solution {
private:
static bool cmp(const vector<int>& a,const vector<int>& b){
return a[0] < b[0];
}
public:
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][1],points[i][1]);
}
}
return result;
}
};
435.无重叠区间
class Solution {
static bool cmp(const vector<int>& a,const vector<int>& b){
return a[0] < b[0];
}
public:
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
if(intervals.size() == 0){
return 0;
}
sort(intervals.begin(),intervals.end(),cmp);
int count = 0;
for(int i=1;i<intervals.size();i++){
if(intervals[i][0] < intervals[i-1][1]){
count++;
intervals[i][1] = min(intervals[i][1],intervals[i-1][1]);
}
}
return count;
}
};
763.划分字母区间
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(i == right){
result.push_back(right - left +1);
left = i+1;
}
}
return result;
}
};