Skip to the content.

反转链表


Contact me:

Blog -> https://cugtyt.github.io/blog/index
Email -> cugtyt@qq.com
GitHub -> Cugtyt@GitHub


来自牛客 剑指offer

题目描述

输入一个链表,反转链表后,输出新链表的表头

ListNode* ReverseList(ListNode* pHead) {
    ListNode* prev = NULL;
    ListNode* curr = pHead;
    ListNode* next = NULL;
    while (curr) {
        next = curr->next;
        curr->next = prev;
        prev = curr;
        curr = next;
    }
    return prev;
}