-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdailytemp.cpp
More file actions
38 lines (33 loc) · 1.01 KB
/
Copy pathdailytemp.cpp
File metadata and controls
38 lines (33 loc) · 1.01 KB
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
29
30
31
32
33
34
35
36
37
38
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& t) {
int n = t.size();
vector<int>ans(n, 0);
stack<int>st;
for(int i = n-1; i >= 0; i--){
while(!st.empty() && t[st.top()] <= t[i]){
st.pop();
}
if(!st.empty()){
ans[i] = st.top() - i;
}
st.push(i);
}
return ans;
// vector<int>res(t.size(), 0);
// for(int i = 0; i < t.size() - 1; i++){
// int c = 0;
// for(int j = i+1; j < t.size(); j++){
// if(t[i] < t[j]){
// c++;
// res[i] = c;
// break;
// }
// else{
// c++;
// }
// }
// }
// return res;
}
};