์ƒˆ์†Œ์‹

๐Ÿงฎ PS

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

  • -

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

 

 

 

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

 

programmers.co.kr

* ํ’€์ด

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

๊ทธ๋ž˜์„œ priorities = [2, 1, 3, 2] ๋ฅผ ์ธ๋ฑ์Šค ๊ฐ’์„ ์ถ”๊ฐ€ํ•œ 2์ค‘ ๋ฆฌ์ŠคํŠธ๋กœ ๋ฐ”๊พธ์–ด์ฃผ์—ˆ๋‹ค. 

priorities = [ [2, 0] ,[1, 1] , [3,2] , [2. 3] ]

์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ์šฐ๋ ค๋˜์—ˆ๋Š”๋ฐ, ๋‹คํ–‰ํžˆ ๊ทธ๋ƒฅ ํ†ต๊ณผ๋˜์—ˆ๋‹ค.

 

* Code - Python

def search_list(priorities, now) :
    for i in priorities :
        if i[0] > now[0] :
            return False
    return True

def solution(priorities, location):
    answer = 0
    for i in range(len(priorities)) :
        priorities[i] = [priorities[i] , i]
    
    while(True):
        now = priorities[0]
        if search_list(priorities, now) :
            answer += 1
            priorities.pop(0)
            if now[1] == location :
                break
        else :
            priorities.append(now)
            priorities.pop(0)
    
    return answer
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.