golang solution


  • 0
    func deleteDuplicates(head *ListNode) *ListNode {
        if head == nil || head.Next == nil {
            return head
        }
        pre := head
        for enode := head.Next; enode != nil; enode = enode.Next {
            if pre.Val != enode.Val {
                pre.Next = enode
                pre = enode
            }
        }
        pre.Next = nil
        return head
    }
    
    

Log in to reply
 

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