Advertisement
nikunjsoni

739

Mar 23rd, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<int> dailyTemperatures(vector<int>& T) {
  4.         int sz = T.size();
  5.         stack< pair<int, int> > s;
  6.         vector<int> ans(sz,0);
  7.        
  8.         for(int i=0; i<sz; i++){
  9.             while(!s.empty() && s.top().first < T[i]){
  10.                 pair<int, int> tmp = s.top();
  11.                 s.pop();
  12.                 ans[tmp.second] = i-tmp.second;
  13.             }
  14.             s.push(make_pair(T[i], i));
  15.         }
  16.         return ans;
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement