Only one while can solve this problem

  • 0
    struct ListNode* deleteDuplicates(struct ListNode* head) {
        if (head == NULL) return NULL;
        struct ListNode* p = head;
        struct ListNode* q = head->next;
        while(q != NULL){
            if (p->val == q->val){
                p->next = q->next;
                q = q->next;
                p = q;
                q = q->next;
        return head;

Log in to reply

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