-
Notifications
You must be signed in to change notification settings - Fork 0
/
detonate-the-maximum-bombs.py
32 lines (27 loc) · 1.01 KB
/
detonate-the-maximum-bombs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution:
def maximumDetonation(self, bombs: List[List[int]]) -> int:
def inbound(bomb1, bomb2):
x1, y1, r1 = bomb1
x2, y2, r2 = bomb2
distance = math.sqrt(((y1 - y2) ** 2) + ((x1 - x2) ** 2))
if distance > r1:
return False
return True
def dfs(bomb_indx, count):
if bomb_indx in visited:
return
visited.add(bomb_indx)
count = 1
for b_indx in range(len((bombs))):
if b_indx not in visited and inbound(bombs[bomb_indx], bombs[b_indx]):
# print(bomb, bombs[b_indx])
count += dfs(b_indx, count)
return count
max_bombs = 0
for bomb_indx in range(len(bombs)):
visited = set()
detonated = dfs(bomb_indx, 0)
# print(bomb, detonated)
max_bombs = max(max_bombs, detonated)
# print()
return max_bombs