class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {
        if (pHead == NULL) {
            return pHead;
        }
        ListNode* newHead = pHead;
        pHead = pHead->next;
        newHead->next = NULL;
        while (pHead != NULL) {
            ListNode* next = pHead->next;
            pHead->next = newHead;
            newHead = pHead;
            pHead = next;
        }
        return newHead;
    }
};