10ms C++ solution


  • 1
    C
    class Solution {
    public:
        ListNode* reverseList(ListNode* head) {
            ListNode *pre = 0, *curr, *next;
            curr = head;
            while (curr)
            {
                next = curr->next;
                curr->next = pre;
                pre = curr;
                curr = next;
            }
            return pre;
        }
    };

Log in to reply
 

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