add new solutions
This commit is contained in:
parent
886b5e0a8e
commit
67cad91898
47 changed files with 1549 additions and 1 deletions
19
solutions/7/q739/solution.go
Normal file
19
solutions/7/q739/solution.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue