20 lines
569 B
Go
20 lines
569 B
Go
// Package q739 implements a solution for https://leetcode.com/problems/daily-temperatures/
|
|
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
|