Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e8a8db4

Browse files
committed
添加 0452.用最少数量的箭引爆气球.md Scala版本
1 parent 7d9d2d1 commit e8a8db4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎problems/0452.用最少数量的箭引爆气球.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,30 @@ impl Solution {
288288
}
289289
}
290290
```
291+
292+
### Scala
293+
294+
```scala
295+
object Solution {
296+
def findMinArrowShots(points: Array[Array[Int]]): Int = {
297+
if (points.length == 0) return 0
298+
// 排序
299+
var point = points.sortWith((a, b) => {
300+
a(0) < b(0)
301+
})
302+
303+
var result = 1 // points不为空就至少需要一只箭
304+
for (i <- 1 until point.length) {
305+
if (point(i)(0) > point(i - 1)(1)) {
306+
result += 1
307+
} else {
308+
point(i)(1) = math.min(point(i - 1)(1), point(i)(1))
309+
}
310+
}
311+
result // 返回结果
312+
}
313+
}
314+
```
315+
291316
-----------------------
292317
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /