19 lines
477 B
Go
19 lines
477 B
Go
package q739
|
|
|
|
func dailyTemperatures(temperatures []int) []int {
|
|
waitDays := make([]int, len(temperatures))
|
|
|
|
idxStack := make([]int, 0, len(temperatures))
|
|
for i, temp := range temperatures {
|
|
for len(idxStack) > 0 && temperatures[idxStack[len(idxStack)-1]] < temp {
|
|
popped := idxStack[len(idxStack)-1]
|
|
idxStack = idxStack[:len(idxStack)-1] // pop
|
|
|
|
waitDays[popped] = i - popped
|
|
}
|
|
idxStack = append(idxStack, i)
|
|
}
|
|
return waitDays
|
|
}
|
|
|
|
var _ = dailyTemperatures
|