迭代法
class Solution {
public:
ListNode* reverseList(ListNode* head) {
if(head==nullptr) return head;
ListNode *p=new ListNode(-1,head);
while(head->next){
ListNode *next=head->next;
head->next=next->next;
next->next=p->next;
p->next=next;
}
return p->next;
}
};