https://programmers.co.kr/learn/courses/30/lessons/64061?language=python
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 1๋จ๊ณ - ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์
def solution(board, moves):
stack_list = []
answer = 0
for move in moves:
for i in range(len(board)):
if board[i][move-1] != 0:
stack_list.append(board[i][move-1])
board[i][move-1] = 0
if len(stack_list) > 1:
if stack_list[-1] == stack_list[-2]:
stack_list.pop(-1)
stack_list.pop(-1)
answer += 2
break
return answer
์ฒ์์ board์ ๋ํด ์ดํด๊ฐ ์๋ผ์ ๊ทธ๋ ค๋ณด๋ฉด์ ์๊ฐ์ ํด๋ณด๋ ์๊ฐ๋ณด๋ค ๋จ์ํ stack์ ์ด์ฉํ ๋ฌธ์ ์๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] [SQL] ์ญ์ ์ ๋ ฌํ๊ธฐ (0) | 2022.03.14 |
---|---|
[Programmers] [SQL] ๋ชจ๋ ๋ ์ฝ๋ ์กฐํํ๊ธฐ (0) | 2022.03.14 |
[Programmers] [2019 KAKAO BLIND RECRUITMENT] [Python] Level1_์คํจ์จ (0) | 2022.03.08 |
[Programmers] [Python] Level1_๋ชจ์๊ณ ์ฌ (0) | 2022.03.08 |
[Programmers] [2020 ์นด์นด์ค ์ธํด์ญ] [Python] Level1_ํคํจ๋ ๋๋ฅด๊ธฐ (0) | 2022.03.07 |