首页 > 其他 > 详细

452. 用最少数量的箭引爆气球

时间:2020-04-18 17:54:29      阅读:53      评论:0      收藏:0      [点我收藏+]
 1 bool cmp(vector<int>& a,vector<int>& b)
 2 {
 3     //第一个数从小到大排列  如果第一个数相等,则第二个数从小到大排列
 4     return a[0] < b[0] || ((a[0] == b[0]) && (a[1] < b[1]));
 5 }
 6 
 7 class Solution 
 8 {
 9 public:
10     int findMinArrowShots(vector<vector<int>>& points) 
11     {
12         sort(points.begin(),points.end(),cmp);
13         int res = 0;
14         if(points.empty() || points[0].empty()) return 0;
15         int begin = points[0][0],end = points[0][1];
16         for(int i = 1;i < points.size();i ++)
17         {
18             if(points[i][1] < end) begin = points[i][0],end = points[i][1];
19             else if(points[i][0] > end) res ++,begin = points[i][0],end = points[i][1];
20             else begin = points[i][0];
21         }
22         return res + 1;
23     }
24 };

 

452. 用最少数量的箭引爆气球

原文:https://www.cnblogs.com/yuhong1103/p/12726857.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!