/*
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 单链表逆序
最新推荐文章于 2021-07-16 09:27:10 发布