leetcode452
public class Solution {
public int FindMinArrowShots(int[,] points)
{
// multidimensional array cannot be sorted directly - copy to objects
Pt[] pts = new Pt[points.GetLength()];
for (int i = ; i < points.GetLength(); i++)
{
pts[i] = new Pt(points[i, ], points[i, ]);
}
Array.Sort(pts, (a, b) => a.start.CompareTo(b.start)); int cnt = ;
Pt prev = null;
for (int i = ; i < pts.Length; i++)
{
if (prev == null || prev.end < pts[i].start)
{
cnt++;
prev = pts[i];
}
else if (pts[i].end < prev.end)
{
prev.end = pts[i].end;
}
}
return cnt;
} public class Pt
{
public int start;
public int end;
public Pt(int s, int e) { start = s; end = e; }
}
}
https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/#/solutions
leetcode452的更多相关文章
- [Swift]LeetCode452. 用最少数量的箭引爆气球 | Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
随机推荐
- ZOJ 3204 Connect them(最小生成树+最小字典序)
Connect them Time Limit: 1 Second Memory Limit: 32768 KB You have n computers numbered from 1 t ...
- Week03-Java学习笔记第三次作业
Week03-面向对象入门 1.本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系. ...
- Build ios app with Delphi Xe4. Lazy Social Talker ready for sale.
Yes, it is build with Delphi XE4. try it. now. What is Lazy Social Talker? Lazy Social Talker is a ...
- 从无到有开发自己的Wordpress博客主题---Wordpress主题的构造
在这篇教程中,主要是对Wordpress的主题的构造进行分析,以方便今后的开发工作. 本来打算就引用一下别人已经有的文档就好了,但还是想从头到尾捋一遍,也方便自己梳理学习. 1.Wordpress主题 ...
- 使用 minio 搭建私有对象存储云。aws-php-sdk 操作object
How to use AWS SDK for PHP with Minio Server aws-sdk-php is the official AWS SDK for the PHP program ...
- 二分答案(Widespread )
二分答案其实是变相贪心,这周算是被这个虐了,怎么都想不到,比如这题,一直纠结在最大值的贪心上后面队友一指点,原来可以先减去x*b,然后a-b随机分配就好了, 仔细一想没错呀,每次攻击必然受到x*b次伤 ...
- LeetCode Design TinyURL
原题链接在这里:https://leetcode.com/problems/design-tinyurl/description/ 题目: How would you design a URL sho ...
- LA2572 Viva Confetti
题意 PDF 分析 两两圆求交点,对每个圆弧按半径抖动. 时间复杂度\(O(T n^2)\) 代码 #include<iostream> #include<cstdio> #i ...
- 最全的Javascript编码规范(推荐)
1.嵌入规则 Javascript程序应该尽量放在.js的文件中,需要调用的时候在页面中以<script src="filename.js">的形式包含进来.Javas ...
- 给System.Timer类的Elapsed事件加锁
背景: 最近在做一个项目,程序是命令行程序,在主程序中开一个线程,这个线程用到了System.Timer类的Elapsed事件,根据指定时间间隔循环去查询数据库,找符合条件的记录,把记录组织成xml对 ...