We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b6dc3f2 commit 595f8f6Copy full SHA for 595f8f6
cpp/0901-online-stock-span.cpp
@@ -0,0 +1,30 @@
1
+class StockSpanner {
2
+public:
3
+
4
+ stack<pair<int, int>> st;
5
+ pair<int, int> pr;
6
+ StockSpanner() {
7
+ pr = {0, 0};
8
+ }
9
10
+ int next(int price) {
11
12
+ int ret = 1;
13
+ while (!st.empty() && price >= pr.first)
14
+ {
15
+ ret += pr.second;
16
+ st.pop();
17
+ if (!st.empty())
18
+ pr = st.top();
19
20
+ st.push(make_pair(price, ret));
21
22
+ return (ret);
23
24
+};
25
26
+/**
27
+ * Your StockSpanner object will be instantiated and called as such:
28
+ * StockSpanner* obj = new StockSpanner();
29
+ * int param_1 = obj->next(price);
30
+ */
0 commit comments