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


京公网安备 11010502036488号