Skip to content

Commit

Permalink
Create: 739-Daily-Temperatures.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Ykhan799 authored Sep 25, 2022
1 parent adeb64e commit 95c7b70
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions go/739-Daily-Temperatures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
func dailyTemperatures(temperatures []int) []int {
result := make([]int, len(temperatures))

for i := len(temperatures) - 1; i >= 0; i-- {
j := i + 1

for j < len(temperatures) && temperatures[j] <= temperatures[i] {
if result[j] <= 0 {
break
}
j += result[j]
}

if j < len(temperatures) && temperatures[j] > temperatures[i] {
result[i] = j - i
}

}
return result
}

0 comments on commit 95c7b70

Please sign in to comment.