Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save inspirit941/9d1a0bf84065087da9d14e7a87e475ee to your computer and use it in GitHub Desktop.

Select an option

Save inspirit941/9d1a0bf84065087da9d14e7a87e475ee to your computer and use it in GitHub Desktop.
# 인형이 있는지 탐색하는 함수
def get_doll(idx, board):
for i in range(len(board[idx-1])):
# 해당 인형이 있으면, 인형의 위치 값을 0으로 수정하고
# 그 인형의 값을 리턴한다.
if board[idx-1][i] != 0:
value = board[idx-1][i]
board[idx-1][i] = 0
return value
return None
def solution(board, moves):
board = list(map(list,zip(*board)))
stack = []
answer = 0
for idx in moves:
value = get_doll(idx, board)
if value is not None:
if not stack:
stack.append(value)
elif stack[-1] == value:
answer += 2
stack.pop()
else:
stack.append(value)
return answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment