739. Daily Temperatures

Posted The Tech Road

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了739. Daily Temperatures相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/daily-temperatures/description/

class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        stack<int> st;
        vector<int> res(temperatures.size());
        for (int i = temperatures.size() -1; i >= 0; i--) {
            while (!st.empty() && temperatures[i] >= temperatures[st.top()])
                st.pop();
            if (st.empty())
                res[i] = 0;
            else
                res[i] = st.top() - i;
            st.push(i);
        }
        return res;
    }
};

 

以上是关于739. Daily Temperatures的主要内容,如果未能解决你的问题,请参考以下文章

739. Daily Temperatures - LeetCode

[栈] leetcode 739 Daily Temperatures

刷题739. Daily Temperatures

LeetCode 739:每日温度 Daily Temperatures

[LeetCode] 739. Daily Temperatures

LeetCode-739 Daily Temperatures Solution (with Java)