File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ fun maximumDetonation (b : Array <IntArray >): Int {
3
+ val adj = HashMap <Int , ArrayList <Int >>().apply {
4
+ for (i in b.indices) {
5
+ for (j in 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
+ fun dfs (i : Int , visit : HashSet <Int >) {
17
+ if (i in visit)
18
+ return
19
+ visit.add(i)
20
+ adj[i]?.forEach {
21
+ dfs(it, visit)
22
+ }
23
+ }
24
+
25
+ var res = 0
26
+ for (i in 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
+ }
You can’t perform that action at this time.
0 commit comments