A few problems
This commit is contained in:
19
daily-temperatures/sol.go
Normal file
19
daily-temperatures/sol.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
func dailyTemperatures(temperatures []int) []int {
|
||||
out := make([]int, len(temperatures))
|
||||
stack := make([][2]int, 0)
|
||||
l := 0
|
||||
for i := range temperatures {
|
||||
if l != 0 && temperatures[i] > stack[l-1][1] {
|
||||
for l != 0 && temperatures[i] > stack[l-1][1] {
|
||||
out[stack[l-1][0]] = i - stack[l-1][0]
|
||||
stack = stack[:l-1]
|
||||
l--
|
||||
}
|
||||
}
|
||||
stack = append(stack, [2]int{i, temperatures[i]})
|
||||
l++
|
||||
}
|
||||
return out
|
||||
}
|
Reference in New Issue
Block a user