문제링크
https://programmers.co.kr/learn/courses/30/lessons/64061
코딩테스트 연습 - 크레인 인형뽑기 게임
[[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4
programmers.co.kr
내풀이
import numpy as np
from collections import deque
def solution(board, moves):
b = np.array(board).T.tolist()
for doll in b:
for i in range(len(b[0])):
try:
doll.remove(0)
except:
continue
answer, s = 0, []
for m in moves:
if len(b[m-1]) >= 1:
s.append(b[m-1][0])
del b[m-1][0]
before_len = len(s)
before = ''
while s != before:
before = s[:]
for i in range(len(s) - 1):
if s[i] == s[i+1]:
del s[i]
del s[i]
break
return before_len - len(s)
피드백
2중 반복문으로 더 깔끔히 짤 수 있음
'코딩 문제 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 비밀지도 (python) (0) | 2022.05.12 |
---|---|
[프로그래머스] 실패율 (python) (0) | 2022.05.09 |
[프로그래머스] 키패드 누르기 (python) (0) | 2022.05.06 |
[프로그래머스] 숫자 문자열과 영단어 (python) (0) | 2022.05.06 |
[프로그래머스] 신규 아이디 추천 (python) (0) | 2022.05.06 |