Skip to content

Commit 6b77a25

Browse files
authored
[20250923] PGM / LV3 / 풍선 터트리기 / 김수연
1 parent b2ed5eb commit 6b77a25

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
public int solution(int[] a) {
5+
int answer = 0;
6+
int n = a.length;
7+
if (n == 1) return 1;
8+
int[] left = new int[n];
9+
int[] right = new int[n];
10+
11+
left[0] = a[0];
12+
for (int i = 1; i < n; i++) {
13+
left[i] = Math.min(left[i - 1], a[i]);
14+
}
15+
16+
right[n - 1] = a[n - 1];
17+
for (int i = n - 2; i >= 0; i--) {
18+
right[i] = Math.min(right[i + 1], a[i]);
19+
}
20+
for (int i = 0; i < n; i++) {
21+
if (i == 0 || i == n-1) answer++;
22+
else {
23+
if (left[i-1] < a[i] && right[i+1] < a[i]) continue;
24+
answer++;
25+
}
26+
}
27+
return answer;
28+
}
29+
}
30+
```

0 commit comments

Comments
 (0)