83. Remove Duplicates from Sorted List

 class Solution {

public:

    ListNode* deleteDuplicates(ListNode* head) {

        if(head==NULL||head->next==NULL) return head;

        ListNode* newHead=deleteDuplicates(head->next);

        if(head->val==newHead->val) return newHead;

        else{

            head->next=newHead;

        }

        return head;

    }

};

Comments

Popular posts from this blog

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones