// 发现重复数值,用个变量保存改数值,依次与后面节点比较,直到找不到第一个不一样的节点,
func deleteDuplication(head ListNode) ListNode {
newHeader := &ListNode{}
preNode := newHeader
for ; head != nil; {
if head.Next != nil && head.Val == head.Next.Val {
value := head.Val
for ; head != nil && head.Val == value; {
head = head.Next
}
} else {
preNode.Next = head
preNode = preNode.Next
head = head.Next
preNode.Next = nil
}
}
return newHeader.Next
}