Skip to content

Commit

Permalink
#19 23.06.29 > 5 > 옥상 정원 꾸미기
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Jun 29, 2023
1 parent 02c282c commit dcfb12b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/bj/gold/5/6198.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";

/**
* [stack 문제]
* - stack의 길이를 이용해 푸는 문제이다. 생각보다 어려운 스택..
* cf. (https://velog.io/@thguss/%EB%B0%B1%EC%A4%80-6198.-%EC%98%A5%EC%83%81-%EC%A0%95%EC%9B%90-%EA%BE%B8%EB%AF%B8%EA%B8%B0-with.-Python)
*/
const input = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split("\n");

const solution = (input) => {
const N = +input[0];
const stack = [];
let answer = 0;

for (let i = 1; i <= N; i++) {
const num = +input[i];
while (stack.length !== 0 && stack[stack.length - 1] <= num) {
stack.pop();
}
stack.push(num);
answer += stack.length - 1;
}
return answer;
};

console.log(solution(input));
1 change: 1 addition & 0 deletions src/bj/gold/5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
| 21 | 21758 | [꿀 따기](./21758.js) | 23.06.10 | X |
| 22 | 9205 | [맥주 마시면서 걸어가기](./9205.js) | 23.06.20 | [23.06.21](./replay/9205.js) |
| 23 | 2493 | [](./2493.js) | 23.06.28 ||
| 24 | 6198 | [옥상 정원 꾸미기](./6198.js) | 23.06.29 |

0 comments on commit dcfb12b

Please sign in to comment.