반응형
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
- BFS
- 쉬운 문제
- 소켓
- 수학
- 알고리즘
- Crawling
- 레벨 1
- type challenge
- 크롤링
- 그래프
- 백준
- 타입스크립트
- 프로그래머스 레벨 2
- 타입 챌린지
- dp
- Nestjs
- typescript
- javascript
- dfs
- ip
- HTTP 완벽 가이드
- 자바스크립트
- Node.js
- 가천대
- 문자열
- TCP
- socket
- HTTP
- Algorithm
- 프로그래머스
Archives
- Today
- Total
kakasoo
[node.js] 예상 대진표 ( 프로그래머스 레벨2 ) 본문
반응형
// 프로그래머스 레벨2 예상 대진표를 풀었습니다.
// 둘 씩 잘라서 계속 붙게 하면 언젠가 만나겠거니, 라는 생각으로 풀었습니다.
const getOneRound = (arr) => {
const answer = [];
for (let i = 0; i < arr.length; i += 2) {
answer.push([arr[i], arr[i + 1]]);
}
return answer;
};
const solution = (n, a, b) => {
let humans = new Array(n).fill(0);
humans[a - 1] = 1;
humans[b - 1] = 1;
let count = 0;
loop1: while (true) {
count++;
humans = getOneRound(humans);
for (let i = 0; i < humans.length; i++) {
if (humans[i].filter((el) => el === 1).length === 2) {
break loop1;
} else if (humans[i].filter((el) => el === 1).length === 1) {
humans[i] = humans[i].filter((el) => el !== 0);
} else {
humans[i].pop();
}
}
humans = humans.flat(Infinity);
}
return count;
};
반응형
'프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
[node.js] 뉴스 클러스터링 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 |
---|---|
[node.js] 배달 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 |
[node.js] 게임 맵 최단 거리 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 |
[node.js] 수식 최대화 ( 프로그래머스 레벨2 ) (0) | 2021.06.30 |
[node.js] 신규 아이디 추천 ( 프로그래머스 레벨1 ) (0) | 2021.06.30 |