原题链接:https://leetcode.com/problems/reverse-linked-list/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
if(!head)//避免链表为空
return head;
ListNode* pre,*cur,*t;
pre = head;
cur = head->next;
head->next = nullptr;
while(cur)
{
t = cur->next;
cur->next = pre;
pre = cur;
cur = t;
}
return pre;
}
};