Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 매일메일
- 리액트
- redux-saga
- java
- 자바
- react-redux
- C++
- 코딩테스트합격자되기
- json-server
- createSlice
- Get
- maeil-mail
- axios
- useDispatch
- 테코테코
- 항해플러스
- 프로그래머스
- 알고리즘
- Python
- programmers
- redux
- 이코테
- Algorithm
- 항해99
- JavaScript
- redux-toolkit
- react-router
- SW
- sw expert academy
- react
Archives
- Today
- Total
Binary Journey
[프로그래머스] 크레인 인형뽑기 게임 본문
반응형
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
참고: https://jokerldg.github.io/algorithm/2021/03/28/crane-doll.html
** Python
from collections import deque
def solution(board, moves):
stacklist = deque()
answer = 0
for move in moves:
for i in range(len(board)):
if board[i][move-1] != 0:
stacklist.appendleft(board[i][move-1])
board[i][move-1] = 0
if len(stacklist) > 1:
if stacklist[0] == stacklist[1]:
stacklist.popleft()
stacklist.popleft()
answer += 2
break
return answer
** Javascript
function solution(board, moves) {
let answer = 0;
let stackList = [];
for (let move of moves) {
for(let i = 0; i < board.length; i++) {
if (board[i][move-1] !== 0) {
stackList.unshift(board[i][move-1]);
board[i][move-1] = 0;
if (stackList.length > 0) {
if (stackList[0] === stackList[1]) {
stackList.shift();
stackList.shift();
answer += 2;
}
}
break;
}
}
}
return answer;
}
반응형
'프로그래머스 > level 1' 카테고리의 다른 글
[프로그래머스] 없는 숫자 더하기 (0) | 2021.11.08 |
---|---|
[프로그래머스] 키패드 누르기 (0) | 2021.11.08 |
[프로그래머스] 음양 더하기 (0) | 2021.11.07 |
[프로그래머스] 내적 (0) | 2021.11.01 |
[프로그래머스] 소수 만들기 (0) | 2021.11.01 |