문제링크: 크레인 인형뽑기 게임
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️ |
| 풀이시간 | 40분 |
| 제출횟수 | 3 |
| 인터넷검색유무 | yes |
🍒 My Code
def solution(board, moves):
answer = 0
item = []
size = len(board)
point = [(size-1) for i in range(size)]
#각 줄마다 제일 위에 있는 인형의 위치를 파악해서 point list에
for x in range(size):
for y in range(size):
if board[y][x]!=0:
point[x]=y
break
#움직여가며 1)point위치를 바꾸고 2)인형을 item에 넣음(같은 인형이면 터침)
for move in moves:
if point[move-1]<size:
if len(item)>0 and item[-1]==board[point[move-1]][move-1]:
answer+=2
item.pop()
else:
item.append(board[point[move-1]][move-1])
point[move-1]+=1
return answer
💡 What I learned
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
-> 확인해가면서 넣고 빼고를 해도 됐다