[ํ๋ก๊ทธ๋๋จธ์ค] (Python) - ํ๋ฆฐํฐ
* ํ์ด
๋ฌธ์ ์ ์ฐ์ฌ์๋ ๊ทธ๋๋ก ๊ตฌํํ๋ค. ๋ค๋ง ์ฐ์ ์์์ ๋ฐ๋ผ์ ์๋ฆฌ๋ฅผ ์ด๋ํด๋ฒ๋ฆฌ๋ฉด ์ฒ์ ์ธ์๋ชฉ๋ก์ ์๋ฆฌ๊ฐ์ ๋ชจ๋ฅด๊ฒ ๋๋ค.
๊ทธ๋์ 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