내가 제출한 정답:
def solution(board, moves):
answer = 0
stack = []
def checkStack(stck):
length = len(stck)
if length < 2:
return False
elif stck[length-1] == stck[length-2]:
stck.pop()
stck.pop()
return True
return False
for move in moves:
for row in board:
if row[move-1]:
stack.append(row[move-1])
row[move-1] = 0
if checkStack(stack): answer += 2
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
'프로그래머스 알고리즘 문제 > Level 1' 카테고리의 다른 글
프로그래머스 Level 1 - 키패드 누르기 (0) | 2020.08.18 |
---|---|
프로그래머스 Level 1 - 2016년 (0) | 2020.08.17 |
프로그래머스 Level 1 - 체육복 (0) | 2020.08.17 |
프로그래머스 Level 1 - 모의고사 (0) | 2020.08.17 |
프로그래머스 Level 1 - 완주하지 못한 선수 (0) | 2020.08.17 |