티스토리 뷰
https://www.acmicpc.net/problem/25556
class Node {
constructor(item) {
this.item = item;
this.prev = null;
}
}
class Stack {
constructor() {
this.top = null;
this.size = 0;
}
empty() {
return this.size === 0;
}
push(item) {
const node = new Node(item);
node.prev = this.top;
this.top = node;
this.size += 1;
}
pop() {
const popItem = this.top;
this.top = this.top.prev;
this.size -= 1;
return popItem.item;
}
}
const [[N], nums] = require('fs')
.readFileSync('./dev/stdin')
.toString()
.trim()
.split('\n')
.map((v) => v.split(' ').map(Number));
const stack1 = new Stack();
const stack2 = new Stack();
const stack3 = new Stack();
const stack4 = new Stack();
for (let i = 0; i < N; i++) {
const target = nums[i];
if (stack1.empty() || stack1.top.item < target) {
stack1.push(target);
} else if (stack2.empty() || stack2.top.item < target) {
stack2.push(target);
} else if (stack3.empty() || stack3.top.item < target) {
stack3.push(target);
} else if (stack4.empty() || stack4.top.item < target) {
stack4.push(target);
} else {
console.log('NO');
process.exit();
}
}
console.log('YES');
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 29766번: DKSH 찾기 (0) | 2023.09.11 |
---|---|
Node.js) 백준 24391번: 귀찮은 해강이 (0) | 2023.09.09 |
Node.js) 백준 22252번: 정보 상인 호석 (0) | 2023.09.07 |
Node.js) 백준 23559번: 밥 (0) | 2023.09.07 |
Node.js) 백준 23834번 : 콘센트 (0) | 2023.09.06 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 다이나믹프로그래밍
- create databases;
- MySQL
- 동적프로그래밍
- 개발자면접
- DB 생성
- MOD
- 다이나밍프로그래밍
- 롱베케이션
- create db
- BFS
- 면접질문
- 투포인터
- 면접비
- 로드나인
- 서버개발
- 투포인터 연습
- 최소공통조상
- 서버점검
- 은둔청년체험
- node.js
- 그래프
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함