Skip to content

Commit 6082f49

Browse files
committed
4024. Nearest Available Drone
1 parent 763a295 commit 6082f49

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
3+
1. 아이디어 : 가장 가까운 범위를 만족하는 드론 찾기
4+
5+
2. 시간복잡도 : O(100)
6+
7+
3. 자료구조/알고리즘 : 계산
8+
9+
*/
10+
11+
class Solution {
12+
public int nearestDrone(int[][] drones, int[] target) {
13+
// 더 가까운 드론 찾기
14+
15+
int idx = -1;
16+
int minDis = 10000000;
17+
18+
for(int i=0; i<drones.length; i++) {
19+
int len = Math.abs(drones[i][0] - target[0]) + Math.abs(drones[i][1] - target[1]);
20+
if(drones[i][2]<len || minDis<=len) continue;
21+
22+
minDis = len;
23+
idx = i;
24+
}
25+
26+
return idx;
27+
}
28+
}

0 commit comments

Comments
 (0)