blob: a1818ffb89f69bf2011e989cb71324aedf6e9484 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
struct Span {
price: i32,
days: i32
}
struct StockSpanner {
spans: Vec<Span>
}
impl StockSpanner {
fn new() -> Self {
StockSpanner {
spans: Vec::new()
}
}
fn next(&mut self, price: i32) -> i32 {
let mut days = 1;
while let Some(span) = self.spans.last() {
if span.price <= price {
days += span.days;
self.spans.pop();
} else {
break;
}
}
self.spans.push(Span{price, days});
days
}
}
fn main() {
let obj = StockSpanner::new();
let ret_1: i32 = obj.next(price);
}
|