题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
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结点



顺丰集团工作强度 303人发布