单调栈

    1. class Solution {
    2. public:
    3. vector<int> dailyTemperatures(vector<int>& T) {
    4. if(!T.size()) return vector<int>();
    5. vector<int> res(T.size(), 0);
    6. stack<int> stk;
    7. for(int i = 0; i < T.size(); i++)
    8. {
    9. while(stk.size() && T[stk.top()] < T[i])
    10. {
    11. res[stk.top()] = i - stk.top();
    12. stk.pop();
    13. }
    14. stk.push(i);
    15. }
    16. return res;
    17. }
    18. };