Concise and Fast, 18ms in C++


  • 1
    Y
    class Solution {
    public:
        ListNode *deleteDuplicates(ListNode *head) {
    		if(!head)
    			return head;
    		ListNode *headrecord=head;
    		while(head->next)
    		{
    			if(head->val==head->next->val)
    			{
    				ListNode *record=head->next->next;
    				delete(head->next);
    				head->next=record;
    			}
    			else
    				head=head->next;
    		}
    		return headrecord;
        }
    };

Log in to reply
 

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