기능개발
https://school.programmers.co.kr/learn/courses/30/lessons/42586
def solution(progresses, speeds):
answer = []
for i in range(len(progresses)):
days = (100 - progresses[i] + speeds[i] - 1) // speeds[i]
answer.append(days)
stack = []
score = answer[0]
count = 1
for i in range(1, len(answer)):
if score >= answer[i]:
count += 1
else:
stack.append(count)
score = answer[i]
count = 1
stack.append(count)
return stack
풀이
days 변수에 100에서 progresses[i]를 빼주고 + speeds[i]를 더해준뒤 1을 뺀다 그리고
그 값에서 speeds를 나누어주면 100이상이 될 때 몇번 걸리는지 값이 나온다.
score라는 변수에 첫번째 값을 저장해주고 score가 answer[i] 보다 크거나 같다면 score가 개발될 동안
answer[i]수도 개발이 되므로 count += 1을 해준다.
만약 answer[i]가 stack에 count를 추가해주고 score를 answer[i]로 기준점을 바꿔준다. 그리고
count를 1로 바꾼다.
'algorithm' 카테고리의 다른 글
| [백준] BFS와 DFS 백준 파이썬, 추천 문제, 누구나 쉽게 DFS BFS 이해시키기 (0) | 2024.08.17 |
|---|---|
| [프로그래머스/python] Lv.2 프로세스 (0) | 2024.08.07 |
| [백준(BOJ)]15650번 : 15650 N과 M (2) - Python(파이썬) - (실버3, 순열과 조합) (2) | 2024.08.01 |
| [프로그래머스/python] Lv.2 2019 카카오 개발자 겨울 인턴십 튜플 (0) | 2024.07.08 |
| [프로그래머스/python] Lv.2 할인 행사 (0) | 2024.07.06 |