链表逆序

tech2024-10-07  19

class Solution { public: ListNode* reverseList(ListNode* head) { ListNode* nextNode = NULL; ListNode* oldNode = head; ListNode* newNode = NULL; while (oldNode != NULL) { nextNode = oldNode->next; oldNode->next = newNode; newNode = oldNode; oldNode = nextNode; } return newNode; } };

 

最新回复(0)