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 ...
随机推荐
- 条款30:透彻了解inline的里里外外。
inline可以带来各种好处: 首先其可以使得消除函数调用带来的开销,再者编译器对这种非函数的代码可以做出更多的优化策略. 但是inline函数首先肯定是会导致程序代码的大小更加的庞大,这样会带来 ...
- Agilent RF fundamentals (6) - Real TX/RX and RF model
LNA:Low-Noise Amplifier PA: Power Amplifier1 VGA: Variable-Gain Amplifier DC input Bias Volatage, B ...
- Flask中的session ,自定义实现 session机制, 和 flask-session组件
session 是基于cookie实现, 保存在服务端的键值对(形式为 {随机字符串:'xxxxxx'}), 同时在浏览器中的cookie中也对应一相同的随机字符串,用来再次请求的 时候验证: 注意 ...
- Arcgis for javascript map操作addLayer详解
本节的内容很简单,说说Arcgis for Javascript里面map对象的addLayer方法.在for JS的API中,addLayer方法有两种,如下图: addLayer方法 在addLa ...
- ng $http 和远程服务器通信的一个服务。
$http({url:'',method:''}).success().error() 简洁写法:$http.get()$http.post()... 注意事项:①要求返回的数据格式是json格式②在 ...
- bulkcopy实现批量插入与更新
public static void UpdateData<T>(List<T> list, string TabelName) { DataTable dt = new Da ...
- ranch实现游戏服务器
在 erlang游戏开发tcp 我们建立起了自己的socket tcp 服务器的基本骨架.当时面对并发情况下,多人同一时刻连接服务器的时候,我们的基本骨架 还是难以应付处理.这就使我不得不想对这样的情 ...
- UVA11168 Airport
题意 PDF 分析 首先发现距离最短的直线肯定在凸包上面. 然后考虑直线一般方程\(Ax+By+C=0\),点\((x_0,y_0)\)到该直线的距离为 \[ \frac{|Ax_0+By_0+C|} ...
- 在django中使用logging
转:http://www.tuicool.com/articles/IV3meeE logging django使用python的内置模块logging来管理自己的日志,logging中四个重要的概念 ...
- webpack新版本4.12应用九(配置文件之模块(module))
这些选项决定了如何处理项目中的不同类型的模块. module.noParse RegExp | [RegExp] RegExp | [RegExp] | function(从 webpack 3.0. ...