LeetCode206. 反转链表
/**
* 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* ans=NULL;
ListNode* p=head;
ListNode* t;
while (p!=NULL){
t=p;
p=p->next;
t->next=ans;
ans=t;
}
return ans;
}
};