/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* ReverseList(ListNode* pHead) { ListNode* ans = new ListNode(-1); ListNode* prev = NULL; while(pHead) { ListNode* temp = pHead->next; //temp保存当前链表的下一个位置pHead->next pHead->next = prev; //当前链表指向prev(prev最开始是NULL,后续可不是NULL哦) prev = pHead; //prev移动到当前链表的头节点pHead pHead = temp; //当前链表变为存储的(还未处理的)链表temp } return prev; } };