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 | 29 | 30 |
Tags
- useDispatch
- 항해99
- SW
- 매일메일
- 이코테
- Get
- react-router
- 자바
- 리액트
- json-server
- java
- react-redux
- C++
- redux
- sw expert academy
- programmers
- redux-saga
- JavaScript
- 항해플러스
- 코딩테스트합격자되기
- 알고리즘
- axios
- maeil-mail
- redux-toolkit
- Python
- 프로그래머스
- Algorithm
- react
- 테코테코
- createSlice
Archives
- Today
- Total
Binary Journey
[프로그래머스] 크레인 인형뽑기 게임 본문
반응형
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
참고: https://jokerldg.github.io/algorithm/2021/03/28/crane-doll.html
프로그래머스 크레인 인형뽑기 게임 (python 파이썬) - Tech
[[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]] [1,5,3,5,1,2,1,4] 4
jokerldg.github.io
** 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 |