题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
struct ListNode* ReverseList(struct ListNode* pHead ) { struct ListNode *p1,*p2,*p3; if(pHead!=NULL) { p1=pHead; while(p1!=NULL) { p2=(struct ListNode *)malloc(sizeof(struct ListNode)); p2->val=p1->val; p2->next=p3; p3=p2; p1=p1->next; if(p1==NULL) break; } return p3; } else return pHead; // write code here }