Golang concise 9ms solution


  • 0

    It looks it's slower than other submissions. Let me know if you have some idea to optimize this code further.

    func deleteDuplicates(head *ListNode) *ListNode {
    	if head == nil {
    		return nil
    	}
    	dummyHead := head
    
    	for head.Next != nil {
    		if head.Val == head.Next.Val {
    			head.Next = head.Next.Next
    			continue
    		}
    		head = head.Next
    	}
    	return dummyHead
    }
    
    

Log in to reply
 

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