1
0

2497.h 650 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // Created by 李洋 on 2024/1/3.
  3. //
  4. #ifndef LEECODE_C_2497_H
  5. #define LEECODE_C_2497_H
  6. #include "../../dataStruct/LinkedList/lists.h"
  7. #include <stack>
  8. using namespace std;
  9. //单调栈
  10. ListNode *removeNodes(ListNode *head) {
  11. stack<ListNode *> S;
  12. S.push(head);
  13. ListNode *temp = head->next;
  14. while (temp) {
  15. while (!S.empty() && temp->val > S.top()->val) {
  16. S.pop();
  17. }
  18. S.push(temp);
  19. temp = temp->next;
  20. }
  21. temp = S.top();
  22. S.pop();
  23. while (!S.empty()) {
  24. S.top()->next = temp;
  25. temp = S.top();
  26. S.pop();
  27. }
  28. return temp;
  29. }
  30. #endif //LEECODE_C_2497_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。