@@ -0,0 +1,1042 @@
+package leetcode;%0A%0Apublic class RemoveDuplicatesfromSortedList %7B%0A%09public static ListNode deleteDuplicates(ListNode head) %7B%0A%09%09if (head == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09ListNode cur = head;%0A%09%09while (cur != null) %7B%0A%09%09%09ListNode node = cur.next;%0A%09%09%09if (node != null && cur.val == node.val) %7B%0A%09%09%09%09if (node.next != null) %7B%0A%09%09%09%09%09cur.next = node.next;%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09cur.next = null;%0A%09%09%09%09%7D%0A%09%09%09%7D else %7B%0A%09%09%09%09cur = cur.next;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return head;%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 %7D;%0A%09%09ListNode link = MakeLinkedList(d);%0A%09%09ListNode result = deleteDuplicates(link);%0A%09%09printLink(link);%0A%09%7D%0A%0A%7D%0A

remove duplicates