Untitled
unknown
plain_text
8 months ago
644 B
3
Indexable
Never
class Solution { public: vector<int> dailyTemperatures(vector<int>& arr) { vector<int>res(arr.size(),0); stack<pair<int,int>>s; //temp,index for(int i=0;i<arr.size();i++){ if(s.empty() || arr[i]<s.top().first){ s.push({arr[i],i}); } else{ while(!s.empty() && arr[i]>s.top().first){ pair<int,int>tmp=s.top(); s.pop(); int days=i-tmp.second; res[tmp.second]=days; } s.push({arr[i],i}); } } return res; } };
Leave a Comment