[JS][프로그래머스 -LEVEL 3 - 기지국설치]

정대만·2023년 9월 5일

코딩테스트

목록 보기
43/51
post-thumbnail

처음에 생각한거

  • 틀린코드가 기억이 안나네..ㅋㅋㅋㅋㅋㅋ
  • 인덱스를 이용해서 장난치는 문제. 완전탐색에 가깝게 풀었다.

코드

function solution(n, stations, w) {
  var answer=0;
  var station_index=0;
    
    for(var i=1; i<=n;i++){
  
        
    //console.log(i)
        if( i>= (stations[station_index])-w && ( i<= (stations[station_index])+w))
            {
                i=(stations[station_index]+w);
                 station_index+=1;
                continue;
         
        
            }
        else{
            answer+=1;
            i+=(2*w);
            
        }
    }
    
    return answer;
}

profile
안녕하세요

0개의 댓글