plzprayme/2021-spring-python-tutoring

7주차

Closed this issue · 1 comments

질문을 올려주세요.

#카카오 겨울 인턴십 크레인 인형뽑기 게임
def solution(board, moves):
    stack = [0]  #0을 넣고 시작해야 out of range 오류가 발생하지 않음
    answer = 0
    
    for i in moves:
        for j in range(len(board[0])):          #비어 있지 않은 칸 찾기
            if board[j][i-1] != 0:
                if board[j][i-1] == stack[-1]:  #스택에 들어가면서 소거 되는 경우
                    board[j][i-1] = 0
                    stack.pop()
                    answer += 2
                else:                           #스택에 들어가면서 소거 되지 않는 경우
                    stack.append(board[j][i-1])
                    board[j][i - 1] = 0
                break
                
    return answer