/
* 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) {
if(!head|| !head->next) return head;
auto l=head,m=l->next;
while (m)
{
auto o=m->next;
m->next=l;
l=m,m=o;
}
head->next=NULL;
return l;
}
};