题解
检查current与下一个的val相等吗,相等就把current.next连到下下个上面,然后重复判断,直到不相等为止
代码
package leetcode type ListNode struct { Val int Next *ListNode } func deleteDuplicates(head *ListNode) *ListNode { current := head for current != nil { for current.Next != nil && current.Val == current.Next.Val { current.Next = current.Next.Next } current = current.Next } return head }