My Accepted 12/16ms C++ Solution


  • 0
    J
    class Solution {
    public:
        ListNode* deleteDuplicates(ListNode* head) {
            if (!head || !head->next) return head;
            ListNode* cur = head;
            while (cur->next)
            {
                while (cur->val == cur->next->val)
                {
                    ListNode* tmp = cur->next;
                    cur->next = cur->next->next;
                    delete tmp; tmp = NULL;
                    if (!cur->next) return head;
                }
                cur = cur->next;
            }
            return head;
        }
    };

Log in to reply
 

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