Skip to content

Commit f5cf22f

Browse files
committed
day29
1 parent f72c50c commit f5cf22f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def nearestDrone(self, drones: list[list[int]], target: list[int]) -> int:
3+
min_dist = float("inf")
4+
ans_idx = -1
5+
tx, ty = target
6+
7+
for idx, (x, y, r) in enumerate(drones):
8+
cal_dist = abs(x - tx) + abs(y - ty)
9+
10+
if cal_dist <= r:
11+
if cal_dist < min_dist:
12+
min_dist = cal_dist
13+
ans_idx = idx
14+
15+
return ans_idx

0 commit comments

Comments
 (0)