/**
* 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* cur = head;
ListNode* ans = NULL;
while(cur){
ListNode* temp = cur -> next;
cur -> next = ans;
ans = cur, cur = temp;
}
return ans;
}
};