452 Minimum Number of Arrows to Burst Balloons
452 Minimum Number of Arrows to Burst Balloons
文章目录
- 452 Minimum Number of Arrows to Burst Balloons
- 1:题目描述
- 2:解决思路
- 3:代码
- 4:正数负数相减超出范围(问题)
- 5:50%
1:题目描述
2:解决思路
- 先排序,从小到大
- 开始 < END 则 整个__开始 = 开始
- 结尾 < END 则 整个 __结尾 = 结尾
- 否则
- NUM++
- 整个__开始 = 新的开始
- 整个__结尾 = 新的结尾
3:代码
class Solution {public int findMinArrowShots(int[][] points) {if(points==null || points.length ==0) return 0;Arrays.sort(points, new Comparator<int[]>() {@Overridepublic int compare(int[] o1, int[] o2) {if(o1[0] <o2[0]) return -1;return 1;}});int result=1,begin=points[0][0],end=points[0][1];for(int i=1;i<points.length;i++){if(points[i][0] <= end){begin=points[i][0];if(points[i][1] < end){end=points[i][1];}}else{result++;begin=points[i][0];end=points[i][1];}}return result;}
}
4:正数负数相减超出范围(问题)
Arrays.sort(points, new Comparator<int[]>() {@Overridepublic int compare(int[] o1, int[] o2) {return o1[0]-o2[0];}});
public int compare(int[] o1, int[] o2) {if(o1[0] <o2[0]) return -1;return 1;}
- 不用减法 直接比较大小
5:50%
452 Minimum Number of Arrows to Burst Balloons相关推荐
- LeetCode 452 Minimum Number of Arrows to Burst Balloons(贪心法)
问题:给出n个气球,已知其在二维平面中的区间[left,right],箭只能竖直向中,气球重叠时,箭仍然可以穿过.问最少需要多少箭. 思路:贪心算法,根据右端点从小到大排序.在遍历区间时,如果当前区间 ...
- leetcode 452. Minimum Number of Arrows to Burst Balloons | 452. 用最少数量的箭引爆气球(左程云:最大线段重合问题)
题目 https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/ 题解 重叠区间问题可以总结为在坐标轴上若干个位 ...
- leetcode算法题--Minimum Number of Arrows to Burst Balloons
原题链接:https://leetcode.com/problems/queue-reconstruction-by-height/ bool cmp(vector<int> a, vec ...
- codeforce 804B Minimum number of steps
cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each ...
- LeetCode——1888. 使二进制字符串字符交替的最少反转次数(Minimum Number of Flips to Make the Binary ...)[中等]——分析及代码(Java)
LeetCode--1888. 使二进制字符串字符交替的最少反转次数[Minimum Number of Flips to Make the Binary String Alternating][中等 ...
- 871. Minimum Number of Refueling Stops
题目: A car travels from a starting position to a destination which is target miles east of the starti ...
- LeetCode刷题:871. Minimum Number of Refueling Stops
LeetCode刷题:871. Minimum Number of Refueling Stops 原题链接:https://leetcode.com/problems/minimum-number- ...
- LeetCode 871. Minimum Number of Refueling Stops 最少加油次数
LeetCode 871. Minimum Number of Refueling Stops 本题是LeetCode 871题,最少加油次数. 题目描述 A car travels from a s ...
- LeetCode871.Minimum Number of Refueling Stops
871.Minimum Number of Refueling Stops(加油站的最小数量) Description Difficulty: hard Example 1: Example 2: E ...
最新文章
- 科大星云诗社动态20211205
- 机器学习基础---超参数和验证集
- 十八般武艺玩转GaussDB(DWS)性能调优:总体调优策略
- Android 应用资源及R文件的位置
- JAVA设计模式(08):结构化-飞锤(Flyweight)
- spring快速入门(二)
- 如何在VirtualBox中安装win7虚拟机?
- 在线教育平台项目——设计 接口定义
- python接口测试第二期_上海悠悠python接口自动化测试第二期视频教程价值1600
- 离散数学程序实现——求关系矩阵的自反和对称闭包——c
- Flask 推理模型,显存一直增长。
- 零基础元宇宙AR Avatar制作教程
- centos怎么把计算机调到桌面,CentOS下命令行和桌面模式的切换方法
- ARM开发板使用GDB调试程序
- bottom sheets_使用Sheetson建立由Google Sheets支持的免费电子邮件列表
- 银河麒麟arm64 qt打包
- 好用的网页扒图插件-ImageAssistant
- 【SSM框架】【怠惰致错】Invalid bound statement (not found)
- compressSlice函数代码跟踪
- Python 多位数字写入CSV文件,避免科学计数法显示,超长数字,超大数字,精度保留
热门文章
- string、wstring、cstring、 char、 tchar、int转换方法
- python操作excel-openpyxl(1)
- rust(14)-if let,while let
- 【深度学习】动漫风格迁移AnimeGANv2,发布线上运行Demo
- 【Python基础】这份 pip 使用小抄,要有全有多全(建议收藏)
- 温州大学《深度学习》课程课件(一)
- 【图文并茂】RNN、LSTM、GRU、ConvLSTM、ConvGRU、ST-LSTM的总结
- spark性能优化 -- spark工作原理
- Learning to Rank:X-wise
- 教师节特辑丨网易云信:素质教育「名师」是如何炼成的?