LeetCode题目
代码实现:GO语言
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func deleteDuplicates(head *ListNode) *ListNode {
if head==nil{
return head
}
slow:=head
fast:=head
for fast!=nil{
if fast.Val!=slow.Val{
slow.Next=fast
slow=slow.Next
}
fast=fast.Next
}
slow.Next=nil
return head
}
解题思路:类似快慢指针 同26题