题解 | #反转链表#
反转链表
https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
struct ListNode *p=pHead,*q=pHead->next,*x;
if(pHead==NULL) return NULL;
if(q==NULL) return pHead;
while(x!=NULL){
x=q->next;
q->next=p;
p=q;
q=x;
}
pHead->next=NULL;
return p;
}
