/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode* res = nullptr,*p = pHead;
while(p)
{
ListNode *temp = p->next;
p->next = res;
res = p;
p = temp;
}
return res;
}
};
翻转单链表
最新推荐文章于 2022-12-15 21:29:08 发布