/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if(!pHead) {
return pHead;
}
ListNode *curr = pHead;
ListNode *prev = nullptr;
while(curr) {
// 保存next
ListNode *next = curr->next;
// 将next指向prev
curr->next = prev;
// 节点前移
prev = curr;
curr = next;
}
return prev;
}
};