83. Remove Duplicates from Sorted List

Posted 阿怪123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了83. Remove Duplicates from Sorted List相关的知识,希望对你有一定的参考价值。

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        Map<Integer,Integer> mp=new HashMap<Integer,Integer>();
        if(head==null)
            return null;
        ListNode temp=head;
        ListNode tail=null;
        while(temp!=null)
        {
            if(mp.containsKey(temp.val))
            {
                if(tail!=null)
                    tail.next=temp.next;
                else
                    head=temp.next;
            }
            else
            {
                mp.put(temp.val,1);
                tail=temp;
            }
            temp=temp.next;
        }
        return head;
    }
}

 

以上是关于83. Remove Duplicates from Sorted List的主要内容,如果未能解决你的问题,请参考以下文章

83. Remove Duplicates from Sorted List

83. Remove Duplicates from Sorted Listeasy

83. Remove Duplicates from Sorted List

83. Remove Duplicates from Sorted List

LeetCode 83. Remove Duplicates from Sorted List

LC_83. Remove Duplicates from Sorted List