💡Problem Solving/Programmers
[프로그래머스] 덧칠하기 (Python)
gom20
2023. 3. 7. 09:24
문제
https://school.programmers.co.kr/learn/courses/30/lessons/161989
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
롤러로 칠한 구역의 마지막 index를 기억했다가
다시 칠할 구역이 해당 index보다 커지면 덧칠횟수를 증가시키고
마지막 index를 갱신한다.
소스코드
def solution(n, m, section):
answer = 0
lastidx = 0
for i in section:
if i > lastidx:
answer += 1
lastidx = i + m -1
return answer