@@ -0,0 +1,1082 @@
+/**%0A *%09Given a sorted linked list, %0A *%09delete all duplicates such that each element appear only once.%0A *%09%0A *%09For example,%0A *%09Given 1-%3E1-%3E2, return 1-%3E2.%0A * %09Given 1_%3E1-%3E2-%3E3-%3E3, return 1-%3E2-%3E3.%0A *%0A *%09Author: matao%0A */%0A%0Aclass ListNode %7B%0A%09int val;%0A%09ListNode next;%0A%09ListNode(int val) %7B%0A%09%09this.val = val;%0A%09%7D%0A%7D%0A%0Apublic class RemoveDuplicatesFromSortedList %7B%0A%09public static ListNode deleteDuplicates(ListNode head) %7B%0A%09%09if(head == null)%0A%09%09%09return null;%0A%09%09ListNode curr = head;%0A%09%09while(curr.next != null) %7B%0A%09%09%09if(curr.next.val == curr.val)%0A%09%09%09%09curr.next = curr.next.next;%0A%09%09%09else%0A%09%09%09%09curr = curr.next;%0A%09%09%7D%0A%09%09return head;%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09ListNode head = new ListNode(1);%0A%09%09head.next = new ListNode(1);%0A%09%09head.next.next = new ListNode(2);%0A%09%09//  1-%3E1-%3E2%0A%09%09ListNode curr = head;%0A%09%09while(curr != null) %7B%0A%09%09%09System.out.print(curr.val + %22-%3E%22);%0A%09%09%09curr = curr.next;%0A%09%09%7D%0A%09%09System.out.println(%22after delete:%22);%0A%09%09deleteDuplicates(head);%0A%09%09curr = head;%0A%09%09while(curr != null) %7B%0A%09%09%09System.out.print(curr.val + %22-%3E%22);%0A%09%09%09curr = curr.next;%0A%09%09%7D%0A%09%09System.out.println();%0A%09%7D%0A%7D%0A

add remove dulicates solution