DevYoon

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ํ”„๋ฆฐํ„ฐ (Python) ๋ณธ๋ฌธ

PS/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ํ”„๋ฆฐํ„ฐ (Python)

gimewn 2022. 4. 26. 15:50

link ๐Ÿ”— https://programmers.co.kr/learn/courses/30/lessons/42587

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ”„๋ฆฐํ„ฐ

์ผ๋ฐ˜์ ์ธ ํ”„๋ฆฐํ„ฐ๋Š” ์ธ์‡„ ์š”์ฒญ์ด ๋“ค์–ด์˜จ ์ˆœ์„œ๋Œ€๋กœ ์ธ์‡„ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์ค‘์š”ํ•œ ๋ฌธ์„œ๊ฐ€ ๋‚˜์ค‘์— ์ธ์‡„๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋ฌธ์ œ๋ฅผ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด ์ค‘์š”๋„๊ฐ€ ๋†’์€ ๋ฌธ์„œ๋ฅผ ๋จผ์ € ์ธ์‡„ํ•˜๋Š” ํ”„๋ฆฐ

programmers.co.kr

 

def solution(priorities, location):
    answer = 0
    while len(priorities) != 0:
        flag = 1
        for idx in range(1, len(priorities)):
            if priorities[idx] > priorities[0]:
                flag = 0
                temp = priorities.pop(0)
                priorities.append(temp)
                if location == 0:
                    location = len(priorities)-1
                else:
                    location -= 1
                break
        if flag:
            if location == 0:
                return answer+1
            else:
                priorities.pop(0)
                answer += 1
                location -= 1
    return answer