小白一枚,记录下自己的解题方法,日后回头看看自己有多菜

class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {

        if (!pHead)
            return nullptr;

        ListNode* pre = pHead; ListNode* cur = pre->next;
        pHead = nullptr; pre->next = pHead;

        while (cur != nullptr)
        {
            ListNode* tmp = cur->next;
            cur->next = pre;
            pre = cur; cur = tmp;
        }
        return pre;
    }
};

实例图示:
图片说明