유형 : 구현
풀이 시간: 15분
def solution(priorities, location):
answer = []
tf = [False for i in range(len(priorities))]
tf[location] = True
cnt = 0
while priorities:
curr = priorities.pop(0)
tfcurr = tf.pop(0)
if priorities and curr < max(priorities):
priorities.append(curr)
tf.append(tfcurr)
else:
cnt += 1
if tfcurr == True:
return cnt
간단한 queue 문제였다.
풀이 자체는 어렵지 않았지만, max(priorities) 에서 자꾸 오류가 나서 애먹었다.
빈 배열에 대해 max할 때 error가 난다는 것을 찾아 해결했다.
'프로그래머스 > Lv. 2' 카테고리의 다른 글
10. 주식가격 (스택/큐) ★★ (0) | 2024.07.18 |
---|---|
9. 다리를 지나는 트럭 ★ (스택/큐, sum함수의 시간 복잡도, deque) (0) | 2024.07.18 |
7. 기능개발 ★(실수) (0) | 2024.07.17 |
6. 전화번호 목록 ★★ (hash table, startswith) (0) | 2024.07.17 |
5. 숫자의 표현 ★ (스킬 체크 lv2) (0) | 2024.07.17 |