题解 | #反转链表#第一次想的三指针做法,之后再改进
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
struct ListNode* ReverseList(struct ListNode* pHead ) { struct ListNode *s,*t; t=s=NULL; if(pHead==NULL) return NULL; while(pHead->next!=NULL){ t=pHead->next; //保存下一个节点 pHead->next=s; //让当前节点指向上一个节点 s=pHead; //保存这一个节点 pHead=t; //节点后移 } pHead->next=s; //最后一个节点再指向前一个节点 return pHead; }