题解 | 反转链表
反转链表
https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
class Solution {
public:
ListNode* ReverseList(ListNode* head) {
ListNode* curr = head;
ListNode* pre = nullptr;
while (curr) {
ListNode* next = curr->next;
curr->next = pre;
pre = curr;
curr = next;
}
return pre;
}
};
查看11道真题和解析
