My short C++ solution


  • 1
    T
    class Solution {
    public:
        ListNode *deleteDuplicates(ListNode *head) {
            ListNode** p = &head;
            while(*p && (*p)->next) {
                ListNode* p1 = *p, *p2 = p1->next;
                while(p2 && p2->val == p1->val) {
                    p2 = p2->next;
                }
                if(p2 != p1->next) {
                    *p = p2;
                } else {
                    p = &(p1->next);
                }
            }
            return head;
        }
    };

  • 0
    N

    Actually, I think this is a solution write in C.


Log in to reply
 

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