Movatterモバイル変換


[0]ホーム

URL:


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

Commita9518fb

Browse files
authored
Create 2101-detonate-the-maximum-bombs.kt
1 parentcd40ef7 commita9518fb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
classSolution {
2+
funmaximumDetonation(b:Array<IntArray>):Int {
3+
val adj=HashMap<Int,ArrayList<Int>>().apply {
4+
for (iin b.indices) {
5+
for (jin b.indices) {
6+
if (i!= j) {
7+
val dX= b[i][0].toDouble()- b[j][0].toDouble()
8+
val dY= b[i][1].toDouble()- b[j][1].toDouble()
9+
if ((b[i][2].toDouble()* b[i][2].toDouble())>= (dX* dX+ dY* dY))
10+
this[i]= getOrDefault(i,ArrayList<Int>()).apply { add(j) }
11+
}
12+
}
13+
}
14+
}
15+
16+
fundfs(i:Int,visit:HashSet<Int>) {
17+
if (iin visit)
18+
return
19+
visit.add(i)
20+
adj[i]?.forEach {
21+
dfs(it, visit)
22+
}
23+
}
24+
25+
var res=0
26+
for (iin b.indices) {
27+
val visit=HashSet<Int>()
28+
dfs(i, visit)
29+
res= maxOf(
30+
res,
31+
visit.size
32+
)
33+
}
34+
35+
return res
36+
}
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp