/
* 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 a=nullptr;
ListNode r=head;
while(r)
{
ListNode* next=r->next;
r->next=a;
a = r;
r = next;
}
return a;
}
};