mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
49
23/10/901.h
Normal file
49
23/10/901.h
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by 李洋 on 2023/10/7.
|
||||
//
|
||||
|
||||
#ifndef LEECODE_C_Q901_H
|
||||
#define LEECODE_C_Q901_H
|
||||
|
||||
#include <stack>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class trendSpanner {
|
||||
public:
|
||||
trendSpanner() {}
|
||||
|
||||
int next(int price) {
|
||||
count = 1;
|
||||
|
||||
if (trend.size() == 0 || price < trend.top()->value) {
|
||||
trend.push(new stock{price, 1});
|
||||
return count;
|
||||
}
|
||||
|
||||
while (!trend.empty() && price >= trend.top()->value) {
|
||||
count += trend.top()->value;
|
||||
stock *temp = trend.top();
|
||||
trend.pop();
|
||||
delete (temp);
|
||||
}
|
||||
|
||||
trend.push(new stock{price, count});
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
struct stock {
|
||||
int key;
|
||||
int value;
|
||||
};
|
||||
stack<stock *> trend;
|
||||
int count;
|
||||
};
|
||||
/**
|
||||
* Your trendSpanner object will be instantiated and called as such:
|
||||
* trendSpanner* obj = new trendSpanner();
|
||||
* int param_1 = obj->next(price);
|
||||
*/
|
||||
|
||||
#endif LEECODE_C_Q901_H
|
||||
Reference in New Issue
Block a user