Skip to content

Commit 50e4604

Browse files
committed
739.daily-temperatures.md
1 parent d611da8 commit 50e4604

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

739.daily-temperatures.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[To Index](/index.md)
2+
---
3+
#739. 每日温度
4+
难度:Medium
5+
> 根据每日 气温 列表,请重新生成一个列表,对应位置的输出是需要再等待多久温度才会升高超过该日的天数。如果之后都不会升高,请在该位置用 0 来代替。
6+
7+
例如,给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]
8+
9+
提示:气温 列表长度的范围是 [1, 30000]。每个气温的值的均为华氏度,都是在 [30, 100] 范围内的整数。
10+
11+
12+
从最后一天开始看,最后一天必定是0;然后前面的跟下一天比较,如果小于则为1,如果大于,则看下一天的结果是否为0,如果是0表示后面没有更高的温度,如果不为零,则和比下一天大的那一天开始比较,一直比较下去。
13+
14+
```
15+
16+
class Solution {
17+
public:
18+
vector<int> dailyTemperatures(vector<int>& T) {
19+
int left=T.size()-2;
20+
int right=left+1;
21+
vector<int>res(T.size(),0);
22+
if(T.size()<2) return res;
23+
while(left>=0)
24+
{
25+
if(T[left]<T[left+1])
26+
{
27+
res[left]=1;
28+
}
29+
else
30+
{
31+
int tmp=1;
32+
int ttmp=res[left+1];
33+
while(ttmp)
34+
{
35+
tmp+=ttmp;
36+
// cout<<tmp<<endl;
37+
if(T[left]<T[left+tmp])
38+
{
39+
res[left] =tmp;
40+
break;
41+
}
42+
ttmp=res[left+tmp];
43+
44+
}
45+
46+
}
47+
left--;
48+
49+
50+
}
51+
return res;
52+
}
53+
};
54+
```
55+
56+
> 执行用时 :108 ms, 在所有 C++ 提交中击败了77.64%的用户
57+
内存消耗 :34.2 MB, 在所有 C++ 提交中击败了7.69%的用户

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
- [724.Find Pivot Index](/724.find_pivot_index.md)
191191
- [728.Self Dividing Numbers](/728.self_dividing_numbers.md)
192192
- [733.Flood Fill](/733.flood_fill.md)
193+
- [739.每日温度](/739.daliy-temperatures.md)
193194
- [744.Find Smallest Letter Greater Than Target](/744.find_smallest_letter_greater_than_target.md)
194195
- [746.Min Cost Climbing Stairs](/746.min_cost_climbing_stairs.md)
195196
- [747.Largest Number At Least Twice Of Others](/747.largest_number_at_least_twice_of_others.md)

index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
- [724.Find Pivot Index](/724.find_pivot_index.md)
191191
- [728.Self Dividing Numbers](/728.self_dividing_numbers.md)
192192
- [733.Flood Fill](/733.flood_fill.md)
193+
- [739.每日温度](/739.daliy-temperatures.md)
193194
- [744.Find Smallest Letter Greater Than Target](/744.find_smallest_letter_greater_than_target.md)
194195
- [746.Min Cost Climbing Stairs](/746.min_cost_climbing_stairs.md)
195196
- [747.Largest Number At Least Twice Of Others](/747.largest_number_at_least_twice_of_others.md)

0 commit comments

Comments
 (0)