Skip to content

Commit 6b9e41a

Browse files
authored
Merge pull request chipbk10#100 from chipbk10/Stack
Stack
2 parents 7bb55a0 + 5596789 commit 6b9e41a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Topics:
22

33
### Handle Duplicate: 115, 730
4-
### Monotonic: 1135
4+
### Monotonic: 1135, 1130, 907, 901, 856, 503, 496, 84, 42, 739
55
### Intervals: 546, 312, 1000, 1353, 1288
66
### Game:
77
### Knapsack: 416, 518, 1049

src/contest/ReadMe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ReadMe {
1212
// dp: 1349[!] 1340[v] 1367[v] 1388[!]
1313
// divide & conquer: 932[!] 514 903[v] 327[x]
1414
// greedy: 1354[!] 1353[x] 1338[v] 1383[!]
15-
// stack: 1190[!] 975[x] 1381[v] 901
15+
// stack: 1190[!] 975[x] 1381[v] 901[v]
1616
// binary search: 1351[v] 1337[v] 1292[!] 1235
1717
// 2 pointers: 1248[*] 1234[v] 986[v] 826
1818
// sliding window: 1208[v] 1040[!] 995[!] 567
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package stack;
2+
3+
import java.util.Stack;
4+
5+
public class Problem901_OnlineStockSpan {
6+
7+
class StockSpanner {
8+
9+
Stack<int[]> stack = new Stack<>();
10+
11+
public StockSpanner() {
12+
}
13+
14+
public int next(int price) {
15+
int res = 1;
16+
while (!stack.isEmpty() && (stack.peek()[0] <= price)) {
17+
res += stack.pop()[1];
18+
}
19+
stack.push(new int[] {price, res});
20+
return res;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)