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

cotato·2021년 5월 7일

https://programmers.co.kr/learn/courses/30/lessons/64061

My Solution

def solution(board, moves):
    
    n = len(board)
    stack = []
    
    count = 0
    
    for m in moves:
        if board[n - 1][m - 1] == 0:
            continue
        
        for i in range(n):
            if board[i][m - 1] != 0:
                stack.append(board[i][m - 1])
                if len(stack) >= 2 and stack[-1] == stack[-2]:
                    count += 2
                    stack.pop()
                    stack.pop()
                board[i][m - 1] = 0
                break
    
    
    return count
profile
coding_potato

0개의 댓글