题目链接:反转链表
题意:
输入一个链表,反转链表后,输出新链表的表头
解题思路:
借助中间节点进行转换
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode* pre = NULL;
while(pHead != NULL){
ListNode* tmp = NULL;
tmp = pHead->next;
pHead->next = pre;
pre = pHead;
pHead = tmp;
}
return pre;
}
};
5426



被折叠的 条评论
为什么被折叠?



