图片:

C++/代码:

class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {
        auto p = pHead; //定义一个新链表
        ListNode* pre = NULL; //定义一个空链表
        while (p){
            auto Head = p->next;//定义一个Head结点
            p->next = pre;
            pre = p;
            p = Head;
        }
        return pre;
    }
};