
https://programmers.co.kr/learn/courses/30/lessons/64061?language=python3
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr




Solution
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
def game(line, board, basket): | |
cnt = 0 | |
for i in range(len(board)): | |
if board[i][line] == 0: | |
continue | |
else: | |
if len(basket) == 0: | |
basket.append(board[i][line]) | |
else: | |
if basket[-1] == board[i][line]: | |
basket.pop(-1) | |
cnt += 2 | |
else: | |
basket.append(board[i][line]) | |
board[i][line] = 0 | |
return cnt | |
return cnt | |
def solution(board, moves): | |
n = len(board) | |
basket = [] | |
answer = 0 | |
for i in moves: | |
answer += game(i-1, board, basket) | |
return answer |
문제 유형 : 스택 / 큐
basket 이라는 스택을 하나 만들고, moves 배열의 값을 차례대로 game 함수에 넘겨주면서 검사한다. 인형을 하나씩 뽑고 스택의 가장 위에 있는 인형과 비교하고 같으면 없애고 다르면 스택에 넣어준다.
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 불량 사용자 / Python / 2019 카카오 개발자 겨울 인턴십 (2) | 2020.06.26 |
---|---|
[프로그래머스] 파일명 정렬 / Python / 2018 KAKAO BLIND RECRUITMENT (0) | 2020.06.21 |
[프로그래머스] 자물쇠와 열쇠 / Python / 2020 KAKAO BLIND RECRUITMENT (0) | 2020.04.21 |
[프로그래머스] 압축 / Python / 2018 KAKAO BLIND RECRUITMENT (0) | 2020.04.21 |
[프로그래머스] 프렌즈4블록 / Python / 2018 KAKAO BLIND RECRUITMENT (0) | 2020.04.19 |
,