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; } };
原文地址:https://www.cnblogs.com/JTechRoad/p/8998068.html
时间: 2024-10-29 20:27:09