티스토리 뷰
enumerate()를 사용해 각 작업의 대기순서를 설정하고 pop(0)을 사용해 가장 앞의 문서를 꺼내고 비교한다.
현재 i의 중요도가 가장 높고 대기순서가 location과 같을 때는 mx - len(importance)를 반환한다.
i의 중요도가 가장 큰 값이 아닐 때는 append()를 사용해 맨 뒤로 보낸다.
i의 중요도가 가장 크나 대기순서가 location과 같지 않을 때는 중요도를 비교할 priorities에서 제일 큰 값을 빼낸다.
문제풀이
def solution(priorities, location):
importance = []
mx = len(priorities)
for e,p in enumerate(priorities):
importance.append((p,e))
while True:
i = importance.pop(0)
if i[0] == max(priorities) and i[1] == location:
return mx - len(importance)
elif i[0] != max(priorities):
importance.append(i)
else:
priorities.remove(max(priorities))'문제 풀이 > Programmers' 카테고리의 다른 글
| [python3][level 2] H-Index (0) | 2019.04.14 |
|---|---|
| [python3][level 2] 쇠막대기 (0) | 2019.04.05 |
| [python3][level 3] 베스트앨범 (0) | 2019.04.04 |
| [python3][level 3] 타일 장식물 (0) | 2019.03.29 |
| [python3][level 2] 위장 (0) | 2019.03.28 |
댓글