We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c35192f + 9210986 commit 8460196Copy full SHA for 8460196
JHLEE325/202511/18 BOJ G5 옥상 정원 꾸미기.md
@@ -0,0 +1,28 @@
1
+```java
2
+import java.io.*;
3
+import java.util.*;
4
+
5
+public class Main {
6
+ public static void main(String[] args) throws Exception {
7
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8
+ int N = Integer.parseInt(br.readLine());
9
10
+ long answer = 0;
11
+ Stack<Integer> stack = new Stack<>();
12
13
+ for (int i = 0; i < N; i++) {
14
+ int height = Integer.parseInt(br.readLine());
15
16
+ while (!stack.isEmpty() && stack.peek() <= height) {
17
+ stack.pop();
18
+ }
19
20
+ answer += stack.size();
21
22
+ stack.push(height);
23
24
25
+ System.out.println(answer);
26
27
+}
28
+```
0 commit comments