标签:temp http 单调栈 题目 tor nbsp tps code class
problem:https://leetcode.com/problems/daily-temperatures/
一道使用单调栈维护(递减序列)的题目,比较简单。
class Solution { public: vector<int> dailyTemperatures(vector<int>& T) { stack<int> sta; int n = T.size(); vector<int> res(n, 0); for (int i = 0; i < n; i++) { while (!sta.empty() && T[i] > T[sta.top()]) { res[sta.top()] = i - sta.top(); sta.pop(); } sta.push(i); } return res; } };
[栈] leetcode 739 Daily Temperatures
标签:temp http 单调栈 题目 tor nbsp tps code class
原文地址:https://www.cnblogs.com/fish1996/p/11268275.html