美文网首页
leetcode:83. Remove Duplicates f

leetcode:83. Remove Duplicates f

作者: 唐僧取经 | 来源:发表于2018-08-22 17:28 被阅读0次

    83. Remove Duplicates from Sorted List

    Description

    Given a sorted linked list, delete all duplicates such that each element appear only once.

    Example 1:

    Input: 1->1->2
    Output: 1->2
    Example 2:

    Input: 1->1->2->3->3
    Output: 1->2->3

    Answer

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

    相关文章

      网友评论

          本文标题:leetcode:83. Remove Duplicates f

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