/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head)
{
ListNode* pre=NULL,* cur=head,* r=NULL;
while(cur!=NULL)
{
r=cur->next;
cur->next=pre;
pre=cur;
cur=r;
}
return pre;
}
};
单链表反转
最新推荐文章于 2024-10-03 21:03:30 发布