剑指 Offer 24. 反转链表 Posted on 2021-06-25 Edited on 2022-11-27 In 剑指 Offer Disqus: Symbols count in article: 377 Reading time ≈ 1 mins. 剑指 Offer 24. 反转链表 12345678910111213141516171819202122/** * 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* pre = nullptr; while(head) { auto next = head->next; head->next = pre; pre = head; head = next; } return pre; }};