(个人水平有限,请见谅!)
题目描述:
输入一个链表,反转链表后,输出新链表的表头。
代码示例:
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode* h = NULL;
for (ListNode* p = pHead; p != NULL; )
{
ListNode* temp = p->next;
p->next = h;
h = p;
p = temp;
}
return h;
}
};