크레인 인형뽑기 게임 (레벨 1)

정은경·2020년 8월 16일
0

1. 문제





2. 나의 풀이

  • 틀린 풀이
def solution(board, moves):
    answer = 0
    dolls = []

    for m in moves:
        while board[m-1]:
            doll = board[m-1].pop()
            if doll > 0:
                dolls.append(doll)
                break

    result = []
    for d in dolls:
        if result and result[-1] == d:
            result.pop()
        else:
            result.append(d)
    return len(dolls) - len(result)
  • 맞은 풀이
def solution(board, moves):
    answer = 0
    dolls = []

    for m in moves:
        for b in board:
            if b[m-1] > 0:
                doll = b[m-1]
                b[m-1] = 0

                if dolls and dolls[-1] == doll:
                    answer += 2
                    dolls.pop()
                else:
                    dolls.append(doll)
                break

    return answer

3. 남의 풀이

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

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

                if len(stacklist) > 1:
                    if stacklist[-1] == stacklist[-2]:
                        stacklist.pop(-1)
                        stacklist.pop(-1)
                        answer += 2     
                break

    return answer

4. 느낀 점

  • 문제를 잘못 이해해서 한참을 해맸다
  • board는 세로가 아니라 가로였다.....
  • 문제를 잘 이해하도록 하자
profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글