package leetcode
import "fmt"
type Node struct {
Val int
res int
}
type StockSpanner struct {
Item []Node
}
func Constructor901() StockSpanner {
stockSpanner := StockSpanner{make([]Node, 0)}
return stockSpanner
}
func (this *StockSpanner) Next(price int) int {
res := 1
if len(this.Item) == 0 {
this.Item = append(this.Item, Node{price, res})
return res
}
for len(this.Item) > 0 && this.Item[len(this.Item)-1].Val <= price {
res = res + this.Item[len(this.Item)-1].res
this.Item = this.Item[:len(this.Item)-1]
}
this.Item = append(this.Item, Node{price, res})
fmt.Printf("this.Item = %v\n", this.Item)
return res
}