본문 바로가기
Online-Judge/Programmers

[Programmers] Python 크레인 인형뽑기 게임

by eungbbang 2022. 7. 17.
반응형

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 


 

def solution(board, moves):
    stack = []
    cnt = 0
    
    for move in moves:
        for i in range(len(board)):
            if board[i][move-1] != 0:
                if stack and stack[-1] == board[i][move-1]:
                    cnt += 2
                    stack.pop()
                else:
                    stack.append(board[i][move-1])
                board[i][move-1] = 0
                break

    return cnt
반응형

댓글