Skip to content

Commit 8edb0c5

Browse files
committed
Programmers_142085 : 디펜스 게임
1 parent ea74351 commit 8edb0c5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int solution(int n, int k, int[] enemy) {
5+
int round = 0;
6+
PriorityQueue<Integer> pq = new PriorityQueue<>();
7+
for(int i=0; i<enemy.length; i++) {
8+
round = i+1;
9+
pq.offer(enemy[i]);
10+
if(k-- > 0) {
11+
continue;
12+
}
13+
int knight = pq.poll();
14+
if(n - knight >= 0) {
15+
n -= knight;
16+
}else {
17+
round--;
18+
break;
19+
}
20+
}
21+
return round;
22+
}
23+
}

0 commit comments

Comments
 (0)