@@ -0,0 +1,1117 @@
+package leetcode;%0A%0Apublic class RemoveDuplicatesfromSortedListII %7B%0A%09public static ListNode deleteDuplicates(ListNode head) %7B%0A%09%09if (head == null %7C%7C head.next == null) %7B%0A%09%09%09return head;%0A%09%09%7D%0A%09%09ListNode pre = new ListNode(0);%0A%09%09pre.next = head;%0A%09%09head = pre;%0A%09%09ListNode p = head;%0A%09%09while (p.next != null) %7B%0A%09%09%09ListNode cur = p.next;%0A%09%09%09while (cur.next != null && cur.val == cur.next.val) %7B%0A%09%09%09%09cur = cur.next;%0A%09%09%09%7D%0A%09%09%09if (p.next != cur) %7B%0A%09%09%09%09p.next = cur.next;%0A%09%09%09%7D else %7B%0A%09%09%09%09p = p.next;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return head.next;%0A%09%7D%0A%0A%09public static ListNode MakeLinkedList(int d%5B%5D) %7B%0A%09%09ListNode head = new ListNode(d%5B0%5D);%0A%09%09ListNode pre = head;%0A%09%09ListNode cur = head;%0A%09%09for (int i = 1; i %3C d.length; i++) %7B%0A%09%09%09cur = new ListNode(d%5Bi%5D);%0A%09%09%09pre.next = cur;%0A%09%09%09pre = cur;%0A%09%09%7D%0A%09%09return head;%0A%09%7D%0A%0A%09public static void printLink(ListNode link) %7B%0A%09%09while (link != null) %7B%0A%09%09%09System.out.print(link.val + %22--%3E%22);%0A%09%09%09link = link.next;%0A%09%09%7D%0A%09%09System.out.println();%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09int d%5B%5D = %7B 1,1,2,2,3 %7D;%0A%09%09ListNode link = MakeLinkedList(d);%0A%09%09ListNode result = deleteDuplicates(link);%0A%09%09printLink(result);%0A%09%7D%0A%7D%0A

remove 2