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.
1 parent 7685e73 commit 5f3b6d0Copy full SHA for 5f3b6d0
typescript/0901-online-stock-span.ts
@@ -0,0 +1,28 @@
1
+class StockSpanner {
2
+ private stack: { price: number; spanDays: number }[];
3
+
4
+ constructor() {
5
+ this.stack = [];
6
+ }
7
8
+ next(price: number): number {
9
+ let span = 1;
10
11
+ while (
12
+ this.stack.length > 0 &&
13
+ this.stack[this.stack.length - 1].price <= price
14
+ ) {
15
+ span += this.stack[this.stack.length - 1].spanDays;
16
+ this.stack.pop();
17
18
19
+ this.stack.push({ price, spanDays: span });
20
+ return span;
21
22
+}
23
24
+/**
25
+ * Your StockSpanner object will be instantiated and called as such:
26
+ * var obj = new StockSpanner()
27
+ * var param_1 = obj.next(price)
28
+ */
0 commit comments