Skip to content

Commit ad021d1

Browse files
committed
feat: add golang solution to leetcode problem: No.0739. Daily Temperatures
1 parent ece08bc commit ad021d1

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

solution/0700-0799/0739.Daily Temperatures/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ public:
9292
};
9393
```
9494
95+
### **Go**
96+
97+
```go
98+
func dailyTemperatures(T []int) []int {
99+
n := len(T)
100+
res := make([]int, n)
101+
stack := make([]int, 0)
102+
for i, v := range T {
103+
for len(stack) != 0 && T[stack[len(stack)-1]] < v {
104+
j := stack[len(stack)-1]
105+
stack = stack[:len(stack)-1]
106+
res[j] = i - j
107+
}
108+
stack = append(stack, i)
109+
}
110+
return res
111+
}
112+
```
113+
95114
### **...**
96115

97116
```

solution/0700-0799/0739.Daily Temperatures/README_EN.md

+19
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ public:
8888
};
8989
```
9090
91+
### **Go**
92+
93+
```go
94+
func dailyTemperatures(T []int) []int {
95+
n := len(T)
96+
res := make([]int, n)
97+
stack := make([]int, 0)
98+
for i, v := range T {
99+
for len(stack) != 0 && T[stack[len(stack)-1]] < v {
100+
j := stack[len(stack)-1]
101+
stack = stack[:len(stack)-1]
102+
res[j] = i - j
103+
}
104+
stack = append(stack, i)
105+
}
106+
return res
107+
}
108+
```
109+
91110
### **...**
92111

93112
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func dailyTemperatures(T []int) []int {
2+
n := len(T)
3+
res := make([]int, n)
4+
stack := make([]int, 0)
5+
for i, v := range T {
6+
for len(stack) != 0 && T[stack[len(stack)-1]] < v {
7+
j := stack[len(stack)-1]
8+
stack = stack[:len(stack)-1]
9+
res[j] = i - j
10+
}
11+
stack = append(stack, i)
12+
}
13+
return res
14+
}

0 commit comments

Comments
 (0)