思路
把每一个元素都头插法插入到一个虚拟节点即可
代码
class Solution {
public:ListNode* reverseList(ListNode* head) {ListNode* dummy_head = new ListNode();dummy_head->next = nullptr;while(head != nullptr){ListNode* cur = head;head = head->next;cur->next = dummy_head->next;dummy_head->next = cur;}return dummy_head->next;}
};