★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-doopznug-he.html
➤若是连接不是山青咏芝的博客园地址,则多是爬取做者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持做者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 104 balloons.git
An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstart and xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons.github
Example:微信
Input: [[10,16], [2,8], [1,6], [7,12]] Output: 2 Explanation: One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons).
在二维空间中有许多球形的气球。对于每一个气球,提供的输入是水平方向上,气球直径的开始和结束坐标。因为它是水平的,因此y坐标并不重要,所以只要知道开始和结束的x坐标就足够了。开始坐标老是小于结束坐标。平面内最多存在104个气球。ide
一支弓箭能够沿着x轴从不一样点彻底垂直地射出。在坐标x处射出一支箭,如有一个气球的直径的开始和结束坐标为 xstart,xend, 且知足 xstart ≤ x ≤ xend,则该气球会被引爆。能够射出的弓箭的数量没有限制。 弓箭一旦被射出以后,能够无限地前进。咱们想找到使得全部气球所有被引爆,所需的弓箭的最小数量。spa
Example:code
输入: [[10,16], [2,8], [1,6], [7,12]] 输出: 2 解释: 对于该样例,咱们能够在x = 6(射爆[2,8],[1,6]两个气球)和 x = 11(射爆另外两个气球)。
744ms
1 class Solution { 2 func findMinArrowShots(_ points: [[Int]]) -> Int { 3 var points = points 4 if points.isEmpty {return 0} 5 points.sort(by: {(_ a:[Int],_ b:[Int]) -> Bool in return a[1] < b[1]}) 6 var res:Int = 1 7 var end:Int = points[0][1] 8 for i in 1..<points.count 9 { 10 if points[i][0] <= end 11 { 12 end = min(end, points[i][1]) 13 } 14 else 15 { 16 res += 1 17 end = points[i][1] 18 } 19 } 20 return res 21 } 22 }