Skip to content

Commit b92dada

Browse files
committed
Time: 39 ms (30.37%), Space: 92 MB (88.75%) - LeetHub
1 parent 2be35f3 commit b92dada

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class StockSpanner {
2+
public:
3+
stack<pair<int,int>> st;
4+
StockSpanner() {
5+
6+
}
7+
8+
int next(int price) {
9+
int ans=1;
10+
while(!st.empty() && st.top().first<=price){
11+
ans+=st.top().second;
12+
st.pop();
13+
}
14+
st.push({price,ans});
15+
return ans;
16+
}
17+
};
18+
19+
/**
20+
* Your StockSpanner object will be instantiated and called as such:
21+
* StockSpanner* obj = new StockSpanner();
22+
* int param_1 = obj->next(price);
23+
*/

0 commit comments

Comments
 (0)