simple C solution


  • 0
    W
    struct ListNode* deleteDuplicates(struct ListNode* head) {
        if(head==NULL) return NULL;
        struct ListNode* preNode=head;
        struct ListNode* currentNode=head->next;
        while(currentNode){
        	if(preNode->val==currentNode->val){
        		struct ListNode* tmp=currentNode->next;
        		preNode->next=tmp;
        		currentNode=tmp;
        	}else{
                preNode=currentNode;
                currentNode=currentNode->next;
            }
        }
        return head;
    }
    

Log in to reply
 

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