/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode *pHead) {
ListNode *pre = nullptr, *cur = pHead, *tmp;
if (pHead == nullptr)
return nullptr;
while(cur){
tmp = cur->next;
cur->next = pre;
pre = cur;
cur = tmp;
}
return pre;
}
};

京公网安备 11010502036488号