/**
* 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 *p=NULL,*q=head;
while(q){
ListNode*tmp=q->next;
q->next=p;
p=q;
q=tmp;
}
return p;
}
};
206. 反转链表
最新推荐文章于 2024-03-05 13:00:07 发布