/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode *temp;
ListNode *p=NULL;
ListNode *q=head;
while(q){
temp=q->next;
q->next=p;
p=q;
q=temp;
}
return p;
}
};
206. 反转链表
最新推荐文章于 2024-08-09 23:16:53 发布