add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent 886b5e0a8e
commit 67cad91898
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
47 changed files with 1549 additions and 1 deletions

View file

@ -0,0 +1,39 @@
package q901
type Price struct {
day int
price int
}
type StockSpanner struct {
days []Price
currentDay int
}
func Constructor() StockSpanner { return StockSpanner{} }
func (s *StockSpanner) Next(price int) int {
s.currentDay++
curr := Price{day: s.currentDay, price: price}
i := len(s.days) - 1
for ; i >= 0; i-- {
if s.days[i].price > curr.price {
break
}
}
s.days = s.days[:i+1]
ret := s.currentDay
if len(s.days) > 0 {
ret = s.currentDay - s.days[len(s.days)-1].day
}
s.days = append(s.days, curr)
return ret
}
/**
* Your StockSpanner object will be instantiated and called as such:
* obj := Constructor();
* param_1 := obj.Next(price);
*/