Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

찌로그

[프로그래머스] level2 프린터 2020_05_29 Python3 본문

Coding

[프로그래머스] level2 프린터 2020_05_29 Python3

찌드 2020. 5. 29. 23:36

https://programmers.co.kr/learn/courses/30/lessons/42587

 

코딩테스트 연습 - 프린터

일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린��

programmers.co.kr

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class att():
    def __init__(self, idx, val):
        self.idx = idx
        self.val = val
def solution(priorities, location):
    modified = []
    #init
    for i in range(len(priorities)):
        modified.append(att(i, priorities[i]));
    tries = 0
    while modified:
        flag = False
        pivot = modified[0]
        maxval = max(i.val for i in modified)
        if pivot.val < maxval:
            modified.append(pivot)
            modified.pop(0)
        else:
            tries += 1
            if pivot.idx == location:
                return tries
            modified.pop(0)
cs
Comments