본문 바로가기

Algorithm

[프로그래머스 Level1] 크레인 인형뽑기 게임

 

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

[[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 = []
    
    for move in moves:
        for k in range(len(board)):
            if board[k][move-1] > 0:
                basket.append(board[k][move-1])
                board[k][move-1] = 0
                if basket[-1:] == basket[-2:-1]:
                    answer += 2
                    basket = basket[:-2]
                break
                
    return answer