[Python] 프로그래머스 - 크레인 인형뽑기
문제 링크
문제 풀이
def bomb(basket):
for i in range(len(basket)-1):
if basket[i]==basket[i+1]:
return True
return False
def solution(board, moves):
answer = 0
basket = []
n = len(board)
dollStack = [[] for i in range(n)]
for i in range(n):
for j in range(n):
if board[i][j]!=0:
dollStack[j].append(board[i][j])
for d in dollStack:
d.reverse()
for move in moves:
index = move-1
if len(dollStack[index]) > 0:
basket.append(dollStack[index].pop())
if bomb(basket):
basket.pop()
basket.pop()
answer+=2
return answer
댓글남기기