-
Notifications
You must be signed in to change notification settings - Fork 0
/
acg_stock_span.cpp
50 lines (38 loc) · 913 Bytes
/
acg_stock_span.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
// tell the num of prev consecutive days
// which prices were smaller than the current one
int main()
{
vector<int> a= {100,80,60,70,60,75,85};
vector<int> ans(a.size(),0);
deque<int> q;
for (int i = 0; i < a.size(); i++)
{
if(q.empty()){
q.push_back(a[i]);
}
else{
while(!q.empty() && q.back()>=a[i]){
q.pop_back();
}
q.push_back(a[i]);
}
// q.push(a[i]);
// while(q.size()>1){
// if(q.front()>=q.back() ){
// q.pop();
// }
// else{
// }
// }
ans[i] = q.size();
}
for (int i = 0; i < a.size(); i++)
{
cout<<ans[i]<<" ";
}
cout<<endl;
cout<<endl;
return 0;
}