首页 > 学院 > 开发设计 > 正文

452. Minimum Number of Arrows to Burst Balloons

2019-11-06 07:48:16
字体:
来源:转载
供稿:网友

经典的区间选点问题,greedy策略

class Solution {public: static bool cmp(pair<int, int>& a,pair<int,int>& b) { if(a.second<b.second) return true; else if(a.second==b.second&&a.first<b.first) return true; else return false; } int findMinArrowShots(vector<pair<int, int>>& points) { if(points.size()==0) return 0; sort(points.begin(),points.end(),cmp); int now=0; int next=1; int count=1; while(next<points.size()) { if(points[now].second>=points[next].first) next++; else { count++; now=next; next++; } } return count; }};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表