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; } };
原文地址:https://www.cnblogs.com/fish1996/p/11268275.html
时间: 2024-11-04 04:59:20