본문 바로가기

Coding Test/Programmers

[프로그래머스/파이썬] 기지국 설치

728x90

 

나의 풀이

import math

def solution(n, stations, w):
    answer = 0
    distances = []
    start = 1
    
    for station in stations:
        distances.append(station - w - start)
        start = station + w + 1
    distances.append(n - start + 1)
    
    for dist in distances:
        if dist > 0:
            answer += math.ceil(dist / (w * 2 + 1))
    
    return answer
반응형