Skip to content

Commit 79c3512

Browse files
authored
[20251122] PGM / Lv2 / 기지국 설치 / 이강현
1 parent 29c05d4 commit 79c3512

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```java
2+
class Solution {
3+
public int solution(int n, int[] stations, int w) {
4+
int answer = 0;
5+
6+
int idx = 1;
7+
for(int station : stations){
8+
if(idx < station - w){
9+
answer += install(idx,station-w-1,w);
10+
}
11+
idx = station+w+1;
12+
if(station+w >= n) break;
13+
}
14+
if(idx <= n){
15+
answer += install(idx,n,w);
16+
}
17+
18+
return answer;
19+
}
20+
public int install(int start, int end, int w){
21+
int range = end - start + 1;
22+
int size = w*2 + 1;
23+
return range%size != 0 ? range/size + 1 : range/size;
24+
}
25+
}
26+
```

0 commit comments

Comments
 (0)