A few problems

This commit is contained in:
2022-05-29 20:21:38 +01:00
parent 2c0204028e
commit 2a7ec7e34b
17 changed files with 228 additions and 1 deletions

19
daily-temperatures/sol.go Normal file
View 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
}