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相关推荐

  1. LeetCode 452 Minimum Number of Arrows to Burst Balloons(贪心法)

    问题:给出n个气球,已知其在二维平面中的区间[left,right],箭只能竖直向中,气球重叠时,箭仍然可以穿过.问最少需要多少箭. 思路:贪心算法,根据右端点从小到大排序.在遍历区间时,如果当前区间 ...

  2. leetcode 452. Minimum Number of Arrows to Burst Balloons | 452. 用最少数量的箭引爆气球(左程云:最大线段重合问题)

    题目 https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/ 题解 重叠区间问题可以总结为在坐标轴上若干个位 ...

  3. leetcode算法题--Minimum Number of Arrows to Burst Balloons

    原题链接:https://leetcode.com/problems/queue-reconstruction-by-height/ bool cmp(vector<int> a, vec ...

  4. 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 ...

  5. LeetCode——1888. 使二进制字符串字符交替的最少反转次数(Minimum Number of Flips to Make the Binary ...)[中等]——分析及代码(Java)

    LeetCode--1888. 使二进制字符串字符交替的最少反转次数[Minimum Number of Flips to Make the Binary String Alternating][中等 ...

  6. 871. Minimum Number of Refueling Stops

    题目: A car travels from a starting position to a destination which is target miles east of the starti ...

  7. LeetCode刷题:871. Minimum Number of Refueling Stops

    LeetCode刷题:871. Minimum Number of Refueling Stops 原题链接:https://leetcode.com/problems/minimum-number- ...

  8. LeetCode 871. Minimum Number of Refueling Stops 最少加油次数

    LeetCode 871. Minimum Number of Refueling Stops 本题是LeetCode 871题,最少加油次数. 题目描述 A car travels from a s ...

  9. LeetCode871.Minimum Number of Refueling Stops

    871.Minimum Number of Refueling Stops(加油站的最小数量) Description Difficulty: hard Example 1: Example 2: E ...

最新文章

  1. 科大星云诗社动态20211205
  2. 机器学习基础---超参数和验证集
  3. 十八般武艺玩转GaussDB(DWS)性能调优:总体调优策略
  4. Android 应用资源及R文件的位置
  5. JAVA设计模式(08):结构化-飞锤(Flyweight)
  6. spring快速入门(二)
  7. 如何在VirtualBox中安装win7虚拟机?
  8. 在线教育平台项目——设计 接口定义
  9. python接口测试第二期_上海悠悠python接口自动化测试第二期视频教程价值1600
  10. 离散数学程序实现——求关系矩阵的自反和对称闭包——c
  11. Flask 推理模型,显存一直增长。
  12. 零基础元宇宙AR Avatar制作教程
  13. centos怎么把计算机调到桌面,CentOS下命令行和桌面模式的切换方法
  14. ARM开发板使用GDB调试程序
  15. bottom sheets_使用Sheetson建立由Google Sheets支持的免费电子邮件列表
  16. 银河麒麟arm64 qt打包
  17. 好用的网页扒图插件-ImageAssistant
  18. 【SSM框架】【怠惰致错】Invalid bound statement (not found)
  19. compressSlice函数代码跟踪
  20. Python 多位数字写入CSV文件,避免科学计数法显示,超长数字,超大数字,精度保留

热门文章

  1. string、wstring、cstring、 char、 tchar、int转换方法
  2. python操作excel-openpyxl(1)
  3. rust(14)-if let,while let
  4. 【深度学习】动漫风格迁移AnimeGANv2,发布线上运行Demo
  5. 【Python基础】这份 pip 使用小抄,要有全有多全(建议收藏)
  6. 温州大学《深度学习》课程课件(一)
  7. 【图文并茂】RNN、LSTM、GRU、ConvLSTM、ConvGRU、ST-LSTM的总结
  8. spark性能优化 -- spark工作原理
  9. Learning to Rank:X-wise
  10. 教师节特辑丨网易云信:素质教育「名师」是如何炼成的?