Golang刷LeetCode 83. 删除排序链表中的重复元素

    科技2022-07-15  119

    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题

    Processed: 0.013, SQL: 8