/**
* 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 == NULL) return head;
ListNode *h = new ListNode(-1);
ListNode *tail = head;
while(tail != NULL)
{
tail = tail -> next;
head -> next = h -> next;
h -> next = head;
head = tail;
}
return h-> next;
}
};