Algorithm/ํ๋ก๊ทธ๋๋จธ์ค
[ํ๋ก๊ทธ๋๋จธ์ค] ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์ (Python)
1. ๋ฌธ์ ์ค๋ช
๋ฌธ์ ๋งํฌ ์
๋ ฅ: boards [[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]] ๋ณด๋์ ์๋ ์ธํ ์ ๋ณด ์ถ๋ ฅ: moves [1,5,3,5,1,2,1,4] ์ธํ์ ์ด๋ ์์น์์ ๋ฝ์์ง 2. ์ฝ๋ def solution(boards, moves): moves = list(map(lambda x : x-1, moves)) #1์ฉ ๋นผ์ฃผ๊ธฐ stack = [0] #index out of range ๋ฐฉ์งํ์ฌ 0 ๋ฃ์ด์ฃผ๊ธฐ(๋งจ ์ฒ์์๋ stack[-2]๋ฅผ ๊ฒ์ฌํ ๊ฒฝ์ฐ์ ๋ฐ์) cnt = 0 for i in moves: for board in boards: if board[i] !=0: stack.append(board[i]) board[i] = ..