zoukankan      html  css  js  c++  java
  • 739. Daily Temperatures

    根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高的天数。如果之后都不会升高,请输入 0 来代替。

    例如,给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]

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

    后面第几个数比自己大

    C++:

     1 class Solution {
     2 public:
     3     vector<int> dailyTemperatures(vector<int>& T) {
     4         stack<int> s ;
     5         vector<int> res(T.size() , 0) ;
     6         for(int i = 0 ; i < T.size() ; i++){
     7             while(!s.empty() && T[i] > T[s.top()]){
     8                 int idx = s.top() ;
     9                 s.pop() ;
    10                 res[idx] = i - idx ;
    11             }
    12             s.push(i) ;
    13         }
    14         return res ;
    15     }
    16 };
  • 相关阅读:
    Super Mario
    SPOJ Count on a tree
    SPOJ DQUERY
    51nod 区间中第K大的数
    POJ2104 K-th Number
    矩阵模板
    Sasha and Array
    MVC RenderSection
    Lazy Acquisition
    .net4.5 await async 简化之后的异步编程模型
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/10860613.html
Copyright © 2011-2022 走看看