Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dfc46fa

Browse files
committed
Add solution and test-cases for problem 739
1 parent e8bf636 commit dfc46fa

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

‎leetcode/701-800/0739.Daily-Temperatures/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# [739.Daily Temperatures][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
Given an array of integers `temperatures` represents the daily temperatures, return an array `answer` such that `answer[i]` is the number of days you have to wait after the i<sup>th</sup> day to get a warmer temperature. If there is no future day for which this is possible, keep `answer[i] == 0` instead.
75

86
**Example 1:**
97

108
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
9+
Input: temperatures = [73,74,75,71,69,72,76,73]
10+
Output: [1,1,4,2,1,1,0,0]
1311
```
1412

15-
## 题意
16-
> ...
17-
18-
## 题解
13+
**Example 2:**
1914

20-
### 思路1
21-
> ...
22-
Daily Temperatures
23-
```go
15+
```
16+
Input: temperatures = [30,40,50,60]
17+
Output: [1,1,1,0]
2418
```
2519

20+
**Example 3:**
21+
22+
```
23+
Input: temperatures = [30,60,90]
24+
Output: [1,1,0]
25+
```
2626

2727
## 结语
2828

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(temperatures []int) []int {
4+
ans := make([]int, len(temperatures))
5+
// 用下表跳?
6+
for idx := 0; idx < len(temperatures)-1; idx++ {
7+
next := idx + 1
8+
for ; next < len(temperatures) && temperatures[next] <= temperatures[idx]; next++ {
9+
}
10+
if next < len(temperatures) {
11+
ans[idx] = next - idx
12+
}
13+
}
14+
15+
return ans
516
}

‎leetcode/701-800/0739.Daily-Temperatures/Solution_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs []int
14+
expect []int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", []int{73, 74, 75, 71, 69, 72, 76, 73}, []int{1, 1, 4, 2, 1, 1, 0, 0}},
17+
{"TestCase2", []int{30, 40, 50, 60}, []int{1, 1, 1, 0}},
18+
{"TestCase3", []int{30, 60, 90}, []int{1, 1, 0}},
1919
}
2020

2121
// 开始测试
@@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
3030
}
3131
}
3232

33-
//压力测试
33+
//压力测试
3434
func BenchmarkSolution(b *testing.B) {
3535
}
3636

37-
//使用案列
37+
//使用案列
3838
func ExampleSolution() {
3939
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /