Golang Iterative Solution


  • 0
    J
    func deleteDuplicates(head *ListNode) *ListNode {
    	p := head
    	for p != nil {
    		next := p.Next
    // Loop until the next values is not equal to current node value
    		for next != nil && next.Val == p.Val {
    			next = next.Next
    		}
    		p.Next = next
    		p = p.Next
    	}
    	return head
    }
    

Log in to reply
 

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