class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if (pHead == nullptr) {
return nullptr;
}
ListNode *pre = nullptr;
ListNode *cur = pHead;
while (cur) {
ListNode *tmp = cur->next; // 保存下个结点
cur->next = pre; // 指针往前指
// 移动指针
pre = cur;
cur = tmp;
}
return pre;
}
};
09-03
107
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)