/**
* 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 *zz=NULL,*p;
while(head){
p=head->next;
head->next=zz;
zz=head;
if(p==NULL)break;
head=p;
}
return head;
}
};
acwing 35. 反转链表
最新推荐文章于 2024-05-02 01:08:01 发布