@@ -161,93 +161,6 @@ private:
161161 */
162162```
163163
164- #### Go
165-
166- ``` go
167- type StockSpanner struct {
168- stk []pair
169- }
170-
171- func Constructor () StockSpanner {
172- return StockSpanner{[]pair{}}
173- }
174-
175- func (this *StockSpanner ) Next (price int ) int {
176- cnt := 1
177- for len (this.stk ) > 0 && this.stk [len (this.stk )-1 ].price <= price {
178- cnt += this.stk [len (this.stk )-1 ].cnt
179- this.stk = this.stk [:len (this.stk )-1 ]
180- }
181- this.stk = append (this.stk , pair{price, cnt})
182- return cnt
183- }
184-
185- type pair struct { price, cnt int }
186-
187- /* *
188- * Your StockSpanner object will be instantiated and called as such:
189- * obj := Constructor();
190- * param_1 := obj.Next(price);
191- */
192- ```
193-
194- #### TypeScript
195-
196- ``` ts
197- class StockSpanner {
198- private stk: number [][];
199-
200- constructor () {
201- this .stk = [];
202- }
203-
204- next(price : number ): number {
205- let cnt = 1 ;
206- while (this .stk .length && this .stk .at (- 1 )[0 ] <= price ) {
207- cnt += this .stk .pop ()[1 ];
208- }
209- this .stk .push ([price , cnt ]);
210- return cnt ;
211- }
212- }
213-
214- /**
215- * Your StockSpanner object will be instantiated and called as such:
216- * var obj = new StockSpanner()
217- * var param_1 = obj.next(price)
218- */
219- ```
220-
221- #### Rust
222-
223- ``` rust
224- use std :: collections :: VecDeque ;
225- struct StockSpanner {
226- stk : VecDeque <(i32 , i32 )>,
227- }
228-
229- /**
230- * `&self` means the method takes an immutable reference.
231- * If you need a mutable reference, change it to `&mut self` instead.
232- */
233- impl StockSpanner {
234- fn new () -> Self {
235- Self {
236- stk : vec! [(i32 :: MAX , - 1 )]. into_iter (). collect (),
237- }
238- }
239-
240- fn next (& mut self , price : i32 ) -> i32 {
241- let mut cnt = 1 ;
242- while self . stk. back (). unwrap (). 0 <= price {
243- cnt += self . stk. pop_back (). unwrap (). 1 ;
244- }
245- self . stk. push_back ((price , cnt ));
246- cnt
247- }
248- }
249- ```
250-
251164<!-- tabs:end -->
252165
253166<!-- solution:end -->
0 commit comments