原地翻转法
struct ListNode {
int val;
struct ListNode *next;
};
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
struct ListNode* pre=NULL;
struct ListNode* cur=pHead;
struct ListNode* next=cur->next;
if(!pHead){
return pHead;
}
//原地反转法
while(cur){
cur->next=pre;
pre=cur;
cur=next;
next=next->next;
}
return pre;
}