aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--739/go.mod3
-rw-r--r--739/main.go42
2 files changed, 45 insertions, 0 deletions
diff --git a/739/go.mod b/739/go.mod
new file mode 100644
index 0000000..4f9d173
--- /dev/null
+++ b/739/go.mod
@@ -0,0 +1,3 @@
+module 739
+
+go 1.19
diff --git a/739/main.go b/739/main.go
new file mode 100644
index 0000000..2870e41
--- /dev/null
+++ b/739/main.go
@@ -0,0 +1,42 @@
+package main
+
+import "fmt"
+
+func dailyTemperaturesDummy(temperatures []int) []int {
+ l := len(temperatures)
+ res := make([]int, l)
+ for i := 0; i < l; i++ {
+ for j := i + 1; j < l; j++ {
+ if temperatures[j] > temperatures[i] {
+ res[i] = j - i
+ break
+ }
+ }
+ }
+
+ return res
+}
+
+func dailyTemperatures(temperatures []int) []int {
+ l := len(temperatures)
+ ret := make([]int, l)
+ stack := make([]int, 0)
+
+ for i := 0; i < l; i++ {
+ for len(stack) > 0 && temperatures[stack[len(stack)-1]] < temperatures[i] {
+ ret[stack[len(stack)-1]] = (i - stack[len(stack)-1])
+ stack = stack[:len(stack)-1]
+ }
+
+ stack = append(stack, i)
+ }
+
+ return ret
+}
+
+func main() {
+ fmt.Println(dailyTemperatures([]int{73, 74, 75, 71, 69, 72, 76, 73}))
+ fmt.Println(dailyTemperatures([]int{30, 40, 50, 60}))
+ fmt.Println(dailyTemperatures([]int{30, 60, 90}))
+ fmt.Println(dailyTemperatures([]int{90, 60, 90}))
+}