1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func deleteDuplicates(head *ListNode) *ListNode { p := &ListNode{ Val: -1000, Next: head, } cur := p for cur != nil { if cur.Next != nil && cur.Next.Next != nil && cur.Next.Val == cur.Next.Next.Val { curVal := cur.Next.Val for cur.Next != nil && curVal == cur.Next.Val { cur.Next = cur.Next.Next } } else { cur = cur.Next } } return p.Next }
|