LeetCode Remove Duplicated from Sorted List

    public ListNode deleteDuplicates(ListNode head) {
        if(head==null || head.next==null)
            return head;
        ListNode pre=head;;
        ListNode p=head.next;
        while(p!=null)
        {
            if(p.val==pre.val)
            {
                pre.next=p.next;
                p=p.next;
            }
            else
            {
                pre=p;
                p=p.next;
            }
        }
        return head;
    }

 

posted @ 2015-07-09 20:21  Maydow  阅读(112)  评论(0编辑  收藏  举报