Skip to content

Commit 16d18cf

Browse files
committed
[BOJ] 1863 스카이라인 쉬운거 (G4)
1 parent 4043f06 commit 16d18cf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

최어진/10주차/260303.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* 백준 1863번: 스카이라인 쉬운거 (2회차) */
2+
3+
const fs = require('fs');
4+
const lines = fs.readFileSync('/dev/stdin').toString().split('\n');
5+
let ptr = 0;
6+
const input = () => lines[ptr++];
7+
8+
// N <= 5 * 10^4
9+
const N = Number(input());
10+
const stack = [];
11+
let answer = 0;
12+
13+
Array.from({ length: N }, () => {
14+
const [x, y] = input()
15+
.split(' ')
16+
.map((n) => +n);
17+
// console.log(x, y);
18+
19+
while (stack.length > 0 && stack[stack.length - 1] > y) {
20+
answer++;
21+
stack.pop();
22+
}
23+
24+
if (stack.length > 0 && stack[stack.length - 1] === y) return;
25+
if (y === 0) return;
26+
stack.push(y);
27+
// console.log(answer, stack, '\n');
28+
});
29+
30+
console.log(answer + stack.length);

0 commit comments

Comments
 (0)