-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path739.cpp
35 lines (33 loc) · 829 Bytes
/
739.cpp
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
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& T) {
stack<int>S;
int i=0;
S.push(i);
int n=T.size();
vector<int>V(n);
map<int,int>mp;
for(int i=1;i<T.size();i++){
int x=T[S.top()];
if(T[i]>x){
while(!S.empty() && T[i]>T[S.top()]){
mp[S.top()]=i;
S.pop();
}
S.push(i);
}
else if(T[i]<=x){
S.push(i);
}
}
for(int i=0;i<T.size();i++){
if(mp.find(i)==mp.end()){
V[i]=0;
}
else{
V[i]=((mp.find(i))->second - (mp.find(i))->first );
}
}
return V;
}
};