Detonate the Maximum Bombs LeetCode solution in Python
1class Solution(object):2def maximumDetonation(self, bombs):3def count(i):4dq, ret = [i], [i]5while len(dq) > 0:6i = dq.pop()7for j in adj[i]:8if j not in ret and j not in dq:9dq.append(j)10ret.append(j)11return len(ret)1213adj = collections.defaultdict(list)14for i in range(len(bombs)):15for j in range(i + 1, len(bombs)):16if (bombs[i][0] - bombs[j][0]) ** 2 + (17bombs[i][1] - bombs[j][1]18) ** 2 <= bombs[i][2] ** 2:19adj[i].append(j)20if (bombs[i][0] - bombs[j][0]) ** 2 + (21bombs[i][1] - bombs[j][1]22) ** 2 <= bombs[j][2] ** 2:23adj[j].append(i)24ret = 025for i in range(len(bombs)):26ret = max(ret, count(i))27return ret