반응형
def solution(board, moves):
doll_location = { i+1 : [] for i in range(len(board)) }
doll_arr = []
result = 0
for i in range(len(board)):
for j in range(len(board[i])):
if board[i][j] != 0:
doll_location[j+1] = [board[i][j]] + doll_location[j+1]
for move in moves:
doll_len = len(doll_location[move])
if doll_len != 0:
if len(doll_arr) != 0:
if doll_arr[-1:][0] == doll_location[move][doll_len-1:][0]:
result += 2
doll_arr.pop()
doll_location[move].pop()
else:
doll_arr.append(doll_location[move][doll_len-1:][0])
doll_location[move].pop()
else:
doll_arr.append(doll_location[move][doll_len-1:][0])
doll_location[move].pop()
return result반응형
'삽집하는 개발들 > 알고리즘' 카테고리의 다른 글
| [17일차][프로그래머스][42576]완주하지 못한 선수 (0) | 2023.07.04 |
|---|---|
| [17일차][프로그래머스][140108]문자열 나누기 (0) | 2023.07.04 |
| [15일차][프로그래머스][2020 카카오 - 67256]키패드 누르기 (0) | 2023.06.29 |
| [14일차][프로그래머스][160586]대충 만든 자판 (0) | 2023.06.27 |
| [14일차][프로그래머스][155652]둘만의 암호 (0) | 2023.06.27 |