-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path739.cpp
More file actions
34 lines (33 loc) · 988 Bytes
/
739.cpp
File metadata and controls
34 lines (33 loc) · 988 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
29
30
31
32
33
34
class Solution {
public:
vector<int> dailyTemperatures(vector<int>& temperatures) {
int temperatures_size = temperatures.size();
std::vector<int> res(temperatures_size, 0);
stack<int> monotonic_stack;
for(int i = 0; i < temperatures_size; i++)
{
while(monotonic_stack.size())
{
int current_value = monotonic_stack.top();
if(temperatures[current_value] < temperatures[i])
{
res[current_value] = i - current_value;
monotonic_stack.pop();
}
else
{
break;
}
}
if((i+1 < temperatures_size) && (temperatures[i] < temperatures[i+1]))
{
res[i] = 1;
}
else
{
monotonic_stack.push(i);
}
}
return res;
}
};