본문 바로가기

IT/알고리즘

[1day 1 solve , 20/07/06] 프로그래머스 크레인 인형 뽑기 lv1

https://programmers.co.kr/learn/courses/30/lessons/64061?language=python3

 

코딩테스트 연습 - 크레인 인형뽑기 게임

[[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4

programmers.co.kr

 

def solution(board, moves):
    answer = 0
    basket = []
    siz = len(board[0])
    li = [0 for i in range(siz)]
    for i in range(siz):
        for j in range(siz):
            if(li[j]==0 and board[i][j] !=0):
                li[j] = siz-i

    for i in moves:
        num = i-1
        if(li[num] == 0):
            continue
        dull = board[(siz-li[num])][num]
        li[num] = li[num] - 1
        if(len(basket)==0):
            basket.append(dull)
        else:
            if(basket[-1]==dull):
                basket.pop()
                answer = answer +2
            else:
                basket.append(dull) 
    return answer