blob: 6d5603814696b71e417eaa212e1a32a5c080e165 (
plain)
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
|
#include "leetcode.h"
class StockSpanner {
public:
stack<pair<int, int>> storage;
int idx = 0;
int next(int price) {
if (storage.empty()) {
storage.push({price, idx++});
return 1;
} else {
while (!storage.empty() && price >= storage.top().first)
storage.pop();
int ans = 0;
ans = storage.empty() ? idx + 1 : idx - storage.top().second;
storage.push({price, idx++});
return ans;
}
}
};
int main() {
StockSpanner *obj = new StockSpanner();
int param_1 = obj->next(price);
}
|