/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode *dummy = new ListNode(-1);
ListNode *pCur = pHead;
ListNode *pNext = nullptr;
while(pCur)
{
pNext = pCur->next;
pCur->next= dummy->next;
dummy->next = pCur;
pCur = pNext;
}
return dummy->next;
}
};
翻转单链表
最新推荐文章于 2023-04-18 20:48:56 发布