class Solution {
public:
ListNode* reverseList(ListNode* head) {
if(head == nullptr) {
return head;
}
ListNode* last = nullptr;
while(head->next) {
auto next = head->next;
head->next = last;
last = head;
head = next;
}
head->next = last;
return head;
}
};