-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay62.cpp
More file actions
28 lines (27 loc) · 782 Bytes
/
Day62.cpp
File metadata and controls
28 lines (27 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& temperatures) {
vector<int> ans(temperatures.size(), 0);
stack <int> st;
for(int i=temperatures.size()-1;i>=0;i--){
if(st.empty()){
st.push(i);
ans[i] = 0;
}
else{
while(!st.empty() && temperatures[i]>=temperatures[st.top()]){
st.pop();
}
if(st.empty()){
ans[i] = 0;
}
// Calculate the wormer day
else{
ans[i] = st.top()-i;
}
st.push(i);
}
}
return ans;
}
};