美文网首页leetcode
83. Remove Duplicates from Sorte

83. Remove Duplicates from Sorte

作者: AnakinSun | 来源:发表于2019-03-24 20:55 被阅读0次

没什么好说的,就是直接遍历,找到符合条件的删除

func deleteDuplicates(head *ListNode) *ListNode {
    cur := head
    for cur != nil && cur.Next != nil {
        if cur.Next.Val == cur.Val {
            cur.Next = cur.Next.Next
        } else {
            cur = cur.Next
        }
    }
    return head
}

相关文章

网友评论

    本文标题:83. Remove Duplicates from Sorte

    本文链接:https://www.haomeiwen.com/subject/ssjpvqtx.html