/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode *prev=NULL,*next;
while(pHead!=NULL)
{
next=pHead->next;
pHead->next=prev;
prev=pHead;
pHead=next;
}
return prev;
}
};
剑指offer 单链表逆序
最新推荐文章于 2023-03-06 07:55:44 发布