Programmers/Level3
기지국 설치
zzunsik
2021. 9. 15. 23:17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
class Solution {
public int solution(int n, int[] stations, int w) {
int answer = 0;
int i = 1, j = 0;
while(i <= n) {
if(j < stations.length && i <= stations[j] + w && i >= stations[j] - w){
i = stations[j] + 1 + w;
j++;
} else {
answer++;
i += 1 + 2 * w;
}
}
return answer;
}
}
|
cs |
인덱스 위치만 잘 조정하면 된다.