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
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