/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* q=nullptr;
auto p=head;
while(p){
auto r=p->next;
p->next=q;
q=p;
p=r;
}
return q;
}
};