@@ -0,0 +1,1315 @@
+package michael.leetcode.linkedlist;%0D%0A%0D%0A/**%0D%0A * Given a sorted linked list, delete all duplicates such that each element%0D%0A * appear only once.%0D%0A * %0D%0A * For example, Given 1-%3E1-%3E2, return 1-%3E2. Given 1-%3E1-%3E2-%3E3-%3E3, return 1-%3E2-%3E3.%0D%0A * %0D%0A * @author Michael Wan.%0D%0A *%0D%0A */%0D%0Apublic class RemoveDuplicateFromSortedList %7B%0D%0A%09public ListNode deleteDuplicates(ListNode head) %7B%0D%0A%09%09// do make sure to check boundaries.%0D%0A%09%09if(head == null %7C%7C head.next == null)%7B%0D%0A%09%09%09return head;%0D%0A%09%09%7D%0D%0A%09%09ListNode result = head;%0D%0A%09%09while(result.next != null)%7B%0D%0A%09%09%09if(result.val == result.next.val)%7B%0D%0A%09%09%09%09result.next = result.next.next;%0D%0A%09%09%09%09continue;%0D%0A%09%09%09%7D%0D%0A%09%09%09result = result.next;%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09return head;%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09ListNode node1 = new ListNode(1);%0D%0A%09%09ListNode node2 = (node1.next = new ListNode(1));%0D%0A%09%09ListNode node3 = (node2.next = new ListNode(2));%0D%0A%09%09ListNode node4 = (node3.next = new ListNode(2));%0D%0A%09%09ListNode node5 = (node4.next = new ListNode(2));%0D%0A%09%09ListNode node6 = (node5.next = new ListNode(6));%0D%0A%0D%0A%09%09ListNode recorderList = new RemoveDuplicateFromSortedList().deleteDuplicates(node1);%0D%0A%09%09printNode(recorderList);%0D%0A%0D%0A%09%7D%0D%0A%0D%0A%09private static void printNode(ListNode node) %7B%0D%0A%09%09while (node != null) %7B%0D%0A%09%09%09System.out.print(String.format(%22%25s-%3E%22, node.val));%0D%0A%09%09%09node = node.next;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%7D%0D%0A

remove duplicate from sorted list.