반응형
문제
- 링크: https://school.programmers.co.kr/learn/courses/30/lessons/12979?language=java
풀이
더보기
class Solution {
public int solution(int n, int[] stations, int w) {
int answer = 0;
int location = 1;
int i = 0;
while (location <= n) {
// && 조건 순서 주의
if (i < stations.length && location >= stations[i] - w) {
location = stations[i] + w + 1;
i++;
} else {
location += 2 * w + 1;
answer++;
}
}
return answer;
}
}
반응형
'코딩테스트 문제집 > Programmers(Lv3)' 카테고리의 다른 글
[Programmers] Lv3: 정수 삼각형(43105) (0) | 2025.02.12 |
---|