Skip to content

Commit

Permalink
739.daily-temperatures.md
Browse files Browse the repository at this point in the history
  • Loading branch information
newdee committed Jun 11, 2020
1 parent d611da8 commit 50e4604
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
57 changes: 57 additions & 0 deletions 739.daily-temperatures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[To Index](/index.md)
---
#739. 每日温度
难度:Medium
> 根据每日 气温 列表,请重新生成一个列表,对应位置的输出是需要再等待多久温度才会升高超过该日的天数。如果之后都不会升高,请在该位置用 0 来代替。
例如,给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]

提示:气温 列表长度的范围是 [1, 30000]。每个气温的值的均为华氏度,都是在 [30, 100] 范围内的整数。


从最后一天开始看,最后一天必定是0;然后前面的跟下一天比较,如果小于则为1,如果大于,则看下一天的结果是否为0,如果是0表示后面没有更高的温度,如果不为零,则和比下一天大的那一天开始比较,一直比较下去。

```
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& T) {
int left=T.size()-2;
int right=left+1;
vector<int>res(T.size(),0);
if(T.size()<2) return res;
while(left>=0)
{
if(T[left]<T[left+1])
{
res[left]=1;
}
else
{
int tmp=1;
int ttmp=res[left+1];
while(ttmp)
{
tmp+=ttmp;
// cout<<tmp<<endl;
if(T[left]<T[left+tmp])
{
res[left] =tmp;
break;
}
ttmp=res[left+tmp];
}
}
left--;
}
return res;
}
};
```

> 执行用时 :108 ms, 在所有 C++ 提交中击败了77.64%的用户
内存消耗 :34.2 MB, 在所有 C++ 提交中击败了7.69%的用户
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
- [724.Find Pivot Index](/724.find_pivot_index.md)
- [728.Self Dividing Numbers](/728.self_dividing_numbers.md)
- [733.Flood Fill](/733.flood_fill.md)
- [739.每日温度](/739.daliy-temperatures.md)
- [744.Find Smallest Letter Greater Than Target](/744.find_smallest_letter_greater_than_target.md)
- [746.Min Cost Climbing Stairs](/746.min_cost_climbing_stairs.md)
- [747.Largest Number At Least Twice Of Others](/747.largest_number_at_least_twice_of_others.md)
Expand Down
1 change: 1 addition & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
- [724.Find Pivot Index](/724.find_pivot_index.md)
- [728.Self Dividing Numbers](/728.self_dividing_numbers.md)
- [733.Flood Fill](/733.flood_fill.md)
- [739.每日温度](/739.daliy-temperatures.md)
- [744.Find Smallest Letter Greater Than Target](/744.find_smallest_letter_greater_than_target.md)
- [746.Min Cost Climbing Stairs](/746.min_cost_climbing_stairs.md)
- [747.Largest Number At Least Twice Of Others](/747.largest_number_at_least_twice_of_others.md)
Expand Down

0 comments on commit 50e4604

Please sign in to comment.