File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[][] } bombs
3
+ * @return {number }
4
+ */
5
+ const maximumDetonation = function ( bombs ) {
6
+ let n = bombs . length , res = 1 , graph = { }
7
+ for ( let i = 0 ; i < n ; i ++ ) {
8
+ for ( let j = 0 ; j < n ; j ++ ) {
9
+ if ( i === j ) continue
10
+ if ( bombAdj ( bombs [ i ] , bombs [ j ] ) ) {
11
+ if ( graph [ i ] == null ) graph [ i ] = [ ]
12
+ graph [ i ] . push ( j )
13
+ }
14
+ }
15
+ }
16
+ function dfs ( node , visited ) {
17
+ for ( const next of ( graph [ node ] || [ ] ) ) {
18
+ if ( ! visited . has ( next ) ) {
19
+ visited . add ( next )
20
+ dfs ( next , visited )
21
+ }
22
+ }
23
+ }
24
+ for ( let i = 0 ; i < n ; i ++ ) {
25
+ const set = new Set ( [ i ] )
26
+ dfs ( i , set )
27
+ res = Math . max ( res , set . size )
28
+ }
29
+
30
+ return res
31
+ } ;
32
+
33
+ function bombAdj ( source , target ) {
34
+ const [ x1 , y1 , r1 ] = source
35
+ const [ x2 , y2 ] = target
36
+ const { abs } = Math
37
+ return abs ( x1 - x2 ) ** 2 + abs ( y1 - y2 ) ** 2 <= r1 ** 2
38
+ }
You can’t perform that action at this time.
0 commit comments