★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(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 }