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: nil, } pre := p cur := head for cur != nil { if pre.Val != cur.Val { pre.Next = cur pre, cur = pre.Next, cur.Next pre.Next = nil } else { cur = cur.Next } } return p.Next }
|