티스토리 뷰

1. 문제

출처 : 프로그래머스

2. 소스코드 ( Python3 )

def search(priorities, next, cnt):

    index = next

    for i in range(cnt-1):

        index += 1

        if index == cnt: index = 0

        if priorities[next] < priorities[index]:

            next = index

   

    return next

 

def solution(priorities, location):

    answer = 0

    # 변수

    next = 0 # 다음에 프린트할 문서 index

    cnt = len(priorities) # 전체 문서 개수

   

    while True:

        # next 찾기

        next = search(priorities, next, cnt)

       

        # 프린트 하기

        answer += 1

        if next == location:

            #print("최종 = ", answer)

            return answer

        priorities[next] = 0

 

3. 고찰

1) 리스트 길이 n만큼 0으로 초기화

list = [0 for i in range(n)]

리스트를 mxn행렬의 0으로 초기화

matrix = [[0 for col in range(n)] for row in range(m)]

 

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
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
글 보관함