Detonate the Maximum Bombs LeetCode solution in Python

1
class Solution(object):
2
def maximumDetonation(self, bombs):
3
def count(i):
4
dq, ret = [i], [i]
5
while len(dq) > 0:
6
i = dq.pop()
7
for j in adj[i]:
8
if j not in ret and j not in dq:
9
dq.append(j)
10
ret.append(j)
11
return len(ret)
12

13
adj = collections.defaultdict(list)
14
for i in range(len(bombs)):
15
for j in range(i + 1, len(bombs)):
16
if (bombs[i][0] - bombs[j][0]) ** 2 + (
17
bombs[i][1] - bombs[j][1]
18
) ** 2 <= bombs[i][2] ** 2:
19
adj[i].append(j)
20
if (bombs[i][0] - bombs[j][0]) ** 2 + (
21
bombs[i][1] - bombs[j][1]
22
) ** 2 <= bombs[j][2] ** 2:
23
adj[j].append(i)
24
ret = 0
25
for i in range(len(bombs)):
26
ret = max(ret, count(i))
27
return ret

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0