首页 > 其他 > 详细

83. Remove Duplicates from Sorted List

时间:2016-04-04 11:37:15      阅读:128      评论:0      收藏:0      [点我收藏+]
/**
 * 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

原文:http://www.cnblogs.com/aguai1992/p/5351461.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!