Last active
June 4, 2020 04:45
-
-
Save DongguemYoo/99378a8db9526e127c0c8bf35739ae9f to your computer and use it in GitHub Desktop.
[코딩테스트] 카카오 인형뽑기.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python으로 푸니까 생각이 더 쉽게 되는듯! | |
풀이과정 | |
1.move에 해당하는 인형을 리스트로 저장을 한다 | |
2. 1의 저장과정 중에서 마지막 저장과 현재 저장이 같고 0이 아니라면 | |
현재 저장된것과 마지막에 저장할것을 저장하지 않고 지우면서 | |
answer에 2를 더하여 준다 | |
def solution(board, moves): | |
answer = 0 | |
items = [] | |
Board_len = len(board) | |
for x in moves: | |
i =0 | |
for i in range(0,Board_len): | |
if board[i][x-1] != 0: | |
if(len(items)>0): | |
if items[len(items)-1] == board[i][x-1]: | |
items = items[:-1] | |
answer+=2 | |
board[i][x - 1] = 0 | |
break | |
else: | |
items.append(board[i][x-1]) | |
board[i][x - 1] = 0 | |
break | |
else: | |
items.append(board[i][x-1]) | |
board[i][x - 1] = 0 | |
break | |
return answer | |
///다른사람 풀이중 신박한것 | |
//일단 담을때에 체크 하지않고 일단 담고 체크한다 | |
//마지막것과 마지막것-1의 결과가 같다면 | |
//pop을 두번하면서 answer+2를 해준다 | |
//pop두번할생각이 | |
def solution(board, moves): | |
answer = 0 | |
tmpList = [] | |
for m in moves: | |
for i in range(0, len(board)): | |
if board[i][m-1] != 0: | |
tmpList.append(board[i][m-1]) | |
board[i][m-1] = 0 | |
if len(tmpList) > 1: | |
if tmpList[len(tmpList)-1] == tmpList[len(tmpList)-2]: | |
tmpList.pop();tmpList.pop() | |
answer = answer + 2 | |
break | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment