mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加 0452.用最少数量的箭引爆气球.md Scala版本
This commit is contained in:
@ -288,5 +288,30 @@ impl Solution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Scala
|
||||||
|
|
||||||
|
```scala
|
||||||
|
object Solution {
|
||||||
|
def findMinArrowShots(points: Array[Array[Int]]): Int = {
|
||||||
|
if (points.length == 0) return 0
|
||||||
|
// 排序
|
||||||
|
var point = points.sortWith((a, b) => {
|
||||||
|
a(0) < b(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
var result = 1 // points不为空就至少需要一只箭
|
||||||
|
for (i <- 1 until point.length) {
|
||||||
|
if (point(i)(0) > point(i - 1)(1)) {
|
||||||
|
result += 1
|
||||||
|
} else {
|
||||||
|
point(i)(1) = math.min(point(i - 1)(1), point(i)(1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result // 返回结果
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||||
|
Reference in New Issue
Block a user