Skip to content

Commit 6ae1eb2

Browse files
committed
feat: add typescript solution to lc problem: No.0901.Online Stock Span
1 parent a5bb2ac commit 6ae1eb2

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

solution/0900-0999/0901.Online Stock Span/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,33 @@ class StockSpanner {
115115
*/
116116
```
117117

118+
### **TypeScript**
119+
120+
```ts
121+
class StockSpanner {
122+
stack: number[][];
123+
constructor() {
124+
this.stack = [];
125+
}
126+
127+
next(price: number): number {
128+
let ans = 1;
129+
while (this.stack.length > 0 && this.stack[0][0] <= price) {
130+
let [p, c] = this.stack.shift();
131+
ans += c;
132+
}
133+
this.stack.unshift([price, ans]);
134+
return ans;
135+
}
136+
}
137+
138+
/**
139+
* Your StockSpanner object will be instantiated and called as such:
140+
* var obj = new StockSpanner()
141+
* var param_1 = obj.next(price)
142+
*/
143+
```
144+
118145
### **C++**
119146

120147
```cpp

solution/0900-0999/0901.Online Stock Span/README_EN.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,33 @@ class StockSpanner {
132132
*/
133133
```
134134

135+
### **TypeScript**
136+
137+
```ts
138+
class StockSpanner {
139+
stack: number[][];
140+
constructor() {
141+
this.stack = [];
142+
}
143+
144+
next(price: number): number {
145+
let ans = 1;
146+
while (this.stack.length > 0 && this.stack[0][0] <= price) {
147+
let [p, c] = this.stack.shift();
148+
ans += c;
149+
}
150+
this.stack.unshift([price, ans]);
151+
return ans;
152+
}
153+
}
154+
155+
/**
156+
* Your StockSpanner object will be instantiated and called as such:
157+
* var obj = new StockSpanner()
158+
* var param_1 = obj.next(price)
159+
*/
160+
```
161+
135162
### **C++**
136163

137164
```cpp
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class StockSpanner {
2+
stack: number[][];
3+
constructor() {
4+
this.stack = [];
5+
}
6+
7+
next(price: number): number {
8+
let ans = 1;
9+
while (this.stack.length > 0 && this.stack[0][0] <= price) {
10+
let [p, c] = this.stack.shift();
11+
ans += c;
12+
}
13+
this.stack.unshift([price, ans]);
14+
return ans;
15+
}
16+
}
17+
18+
/**
19+
* Your StockSpanner object will be instantiated and called as such:
20+
* var obj = new StockSpanner()
21+
* var param_1 = obj.next(price)
22+
*/

0 commit comments

Comments
 (0)