题解 | #反转链表#笨蛋方法
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
if(!pHead)
return pHead;
struct ListNode *p,*x;
struct ListNode *head;
head=(struct ListNode*)malloc(sizeof(struct ListNode));
head->next=NULL;
p=pHead;
while(p)
{
x = (struct ListNode*)malloc(sizeof(struct ListNode));
x->val=p->val;
x->next=head->next;
head->next=x;
p=p->next;
}
return head->next;
}