题目描述
输入一个链表,反转链表后,输出新链表的表头。
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* head)
{
ListNode * next = NULL;
ListNode * ret = NULL;
if(head == NULL)
return ret;
while(head)
{
next = head->next;
head->next = ret;
ret = head;
head = next;
}
return ret;
}
};