Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Programmers
- 함수형 인터페이스
- 프로그래머스
- 형태소 분석기
- 모바일
- 파일 저장
- jsp
- 자바스크립트
- 프로그래밍
- Python
- 코딩
- jdbc
- java
- n^2 배열 자르기
- 메모장
- javascript
- 셀레니움
- 세션
- 유튜브
- 크롤링
- 파이썬
- android
- 이진 변환 반복하기
- 개발자
- MySQL
- 데이터베이스
- 개발
- js
- 자바
- 입출력
Archives
- Today
- Total
개인용 복습공간
프로그래머스 - 크레인 인형뽑기 게임 본문
board를 변환 후 shift()로 뽑아서 동일한 인형이면 pop() 시키기
function solution(board, moves) {
board = board.map((item, idx) => item.reduce((acc, el, lvl) => {
if (board[lvl][idx] != 0) {
acc.push(board[lvl][idx]);
}
return acc;
}, []));
let temp = [];
return moves.reduce((rs, el) => {
const picker = board[el - 1].shift();
if(picker){
if (temp[temp.length - 1] == picker) {
temp.pop();
rs += 2;
}else{
temp.push(picker);
}
}
return rs;
}, 0);
}
'programmers' 카테고리의 다른 글
프로그래머스 - n^2 배열 자르기 (0) | 2023.10.25 |
---|---|
프로그래머스 - 이진 변환 반복하기 (0) | 2023.10.12 |
프로그래머스 - 키패드 누르기 (0) | 2023.10.12 |
프로그래머스 - H-Index (JavaScript, js) (0) | 2023.10.12 |
Comments