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 ...
随机推荐
- 【pat-1074】宇宙无敌加法器(高精度)
链接:https://www.patest.cn/contests/pat-b-practise/1074 地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的.而在PAT星人开挂的世界里,每 ...
- Makefile的补充学习2
Makefile中使用通配符(1)* 若干个任意字符(2)? 1个任意字符(3)[] 将[]中的字符依次去和外面的结合匹配 还有个%,也是通配符,表示任意多个字符,和*很相似,但是%一般只用于规则描述 ...
- Qt中切换窗口功能的实现
两条语句就能够实现了: this->newNC.setWindowFlags(Qt::WindowStaysOnTopHint); this->newNC.show(); mark一下,防 ...
- c#如何保存richtextbox的rtf格式
C# codethis.rtbText.Rtf = @"{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052" + @&qu ...
- jQuery对象[0]倒底是什么?
s[0]倒底是什么?(s为jQuery对象)代码:var s=$("div"); alert(s.length);alert(s[0]); jQuery对象默认都有个0索引,s为j ...
- BloomFilter布隆过滤器使用
从上一篇可以得知,BloomFilter的关键在于hash算法的设定和bit数组的大小确定,通过权衡得到一个错误概率可以接受的结果. 算法比较复杂,也不是我们研究的范畴,我们直接使用已有的实现. go ...
- 小晚wan的公众号
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70932630 本文出自[我是干勾鱼的博客] 小晚wan的公众号还是挺深刻的,有时 ...
- volatile与const综合分析
在C/C++ 编程中,volatile与const关键字一向容易让人困惑,当然,新手可能从来不用,但是 在高质量和稳健的程序中,这两个关键字 是相当重要的. 相比const,volatile关键字的发 ...
- 人生苦短之我用Python篇(深浅拷贝、常用模块、内置函数)
深浅拷贝 有时候,尤其是当你在处理可变对象时,你可能想要复制一个对象,然后对其做出一些改变而不希望影响原来的对象.这就是Python的copy所发挥作用的地方. 定义了当对你的类的实例调用copy.c ...
- I.MX6 change boot partition 1 to User area
/************************************************************************************ * I.MX6 change ...