File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 203
203
| 05 | ⭐️ | [ Baekjoon-2867 수열의 값] ( ./src/Stack/P2867 ) | |
204
204
| 06 | | [ SWEA-1218 괄호 짝짓기] ( ./src/Stack/swea1218 ) | |
205
205
| 07 | | [ SWEA-1223 계산기2] ( ./src/Stack/swea1223 ) | |
206
+ | 08 | | [ Programmers 주식가격] ( ./src/Stack/prg42584 ) | |
206
207
207
208
### Queue
208
209
Original file line number Diff line number Diff line change
1
+ ## [ programmers - 스택/큐] 주식가격
2
+
3
+ ![ image] ( https://user-images.githubusercontent.com/22045163/115883783-2600e600-a489-11eb-86ed-42fb02091879.png )
Original file line number Diff line number Diff line change
1
+ package Stack .prg42584 ;
2
+
3
+ import java .util .*;
4
+
5
+ class Solution {
6
+ public int [] solution (int [] prices ) {
7
+
8
+ int N = prices .length ;
9
+ int [] res = new int [N ];
10
+ Stack <Price > s = new Stack <>();
11
+
12
+ for (int i = 0 ; i < N ; i ++) {
13
+ int cur = i == N -1 ? 0 : prices [i ];
14
+ while (!s .isEmpty () && s .peek ().price > cur ) {
15
+ Price p = s .pop ();
16
+ res [p .time ] = i - p .time ;
17
+ }
18
+ s .push (new Price (cur , i ));
19
+ }
20
+
21
+ return res ;
22
+ }
23
+ }
24
+
25
+ class Price {
26
+ int price , time ;
27
+
28
+ public Price (int price , int time ) {
29
+ this .price = price ;
30
+ this .time = time ;
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments