2019 카카오 개발자 겨울 인턴십 (lv1)


정답코드

def solution(board, moves):
    answer = 0
    stack = []
    height = len(board[0])
    current = [0 for i in range(height)]

    for i in range(height):
        for j in range(height):
            if board[j][i] != 0:
                current[i] = j
                break
    for m in moves:
        if current[m - 1] < height:
            stack.append(board[current[m - 1]][m - 1])
            current[m - 1] += 1
            while len(stack) > 1 and stack[-1] == stack[-2]:
                answer += 2
                del stack[-2:]


    return answer

정답코드2

def solution(board, moves):
    answer = 0
    stack = []

    for i in moves:
        for j in range(len(board)):
            if board[j][i - 1] != 0:
                stack.append(board[j][i - 1])
                board[j][i - 1] = 0

                if len(stack) > 1:
                    if stack[-1] == stack[-2]:
                        answer += 2
                        del stack[-2:]
                break

    return answer

좋은 웹페이지 즐겨찾기