Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
330 B
2
Indexable
Never
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        ListNode *temp = nullptr, *prev = nullptr;

        while(head)
        {
            temp = head->next;
            head->next = prev;
            prev = head;            
            head = temp;
        }

        return prev;
    }
};
Leave a Comment