class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
/*ListNode *pre=NULL;
while(pHead)
{
ListNode *p=pHead->next;
pHead->next=pre;
pre=pHead;
pHead=p;
}
return pre;
*/
if(!pHead||!pHead->next)
return pHead;
ListNode *next=pHead->next,*p=ReverseList(next);
pHead->next=NULL;
next->next=pHead;
return p;
}
};pre为反转后结点的每个next结点

京公网安备 11010502036488号