Sharing my simple C++ solution


  • 1
    S
    class Solution {
    public:
        ListNode* reverseList(ListNode* head) {
            ListNode* newHead = NULL;
            while (head) {
                ListNode* next = head->next;
                head->next = newHead;
                newHead = head;
                head=next;
            }
            return newHead;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.