Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> dailyTemperatures(vector<int>& t) {
- int n = t.size();
- vector<int> ans(n,0);
- stack<pair<int,int>> st;
- for(int i = 0; i<n; i++){
- if(st.size()!=0 && t[i]> st.top().first){
- while(st.size()!=0 && t[i]>st.top().first){
- ans[st.top().second] = i - st.top().second;
- st.pop();
- }
- }
- st.push({t[i],i});
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement