901.h 951 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // Created by 李洋 on 2023/10/7.
  3. //
  4. #ifndef LEECODE_C_Q901_H
  5. #define LEECODE_C_Q901_H
  6. #include <stack>
  7. using namespace std;
  8. class trendSpanner {
  9. public:
  10. trendSpanner() {}
  11. int next(int price) {
  12. count = 1;
  13. if (trend.size() == 0 || price < trend.top()->value) {
  14. trend.push(new stock{price, 1});
  15. return count;
  16. }
  17. while (!trend.empty() && price >= trend.top()->value) {
  18. count += trend.top()->value;
  19. stock *temp = trend.top();
  20. trend.pop();
  21. delete (temp);
  22. }
  23. trend.push(new stock{price, count});
  24. return count;
  25. }
  26. private:
  27. struct stock {
  28. int key;
  29. int value;
  30. };
  31. stack<stock *> trend;
  32. int count;
  33. };
  34. /**
  35. * Your trendSpanner object will be instantiated and called as such:
  36. * trendSpanner* obj = new trendSpanner();
  37. * int param_1 = obj->next(price);
  38. */
  39. #endif LEECODE_C_Q901_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。