mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			650 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			650 B
		
	
	
	
		
			C++
		
	
	
	
	
	
//
 | 
						|
// Created by 李洋 on 2024/1/3.
 | 
						|
//
 | 
						|
 | 
						|
#ifndef LEECODE_C_2497_H
 | 
						|
#define LEECODE_C_2497_H
 | 
						|
 | 
						|
#include "../../dataStruct/LinkedList/lists.h"
 | 
						|
#include <stack>
 | 
						|
 | 
						|
using namespace std;
 | 
						|
 | 
						|
//单调栈
 | 
						|
ListNode *removeNodes(ListNode *head) {
 | 
						|
    stack<ListNode *> S;
 | 
						|
    S.push(head);
 | 
						|
    ListNode *temp = head->next;
 | 
						|
    while (temp) {
 | 
						|
        while (!S.empty() && temp->val > S.top()->val) {
 | 
						|
            S.pop();
 | 
						|
        }
 | 
						|
        S.push(temp);
 | 
						|
        temp = temp->next;
 | 
						|
    }
 | 
						|
    temp = S.top();
 | 
						|
    S.pop();
 | 
						|
    while (!S.empty()) {
 | 
						|
        S.top()->next = temp;
 | 
						|
        temp = S.top();
 | 
						|
        S.pop();
 | 
						|
    }
 | 
						|
    return temp;
 | 
						|
}
 | 
						|
 | 
						|
#endif //LEECODE_C_2497_H
 |