@@ -0,0 +1,1701 @@
+package michael.leetcode.linkedlist;%0D%0A%0D%0A/**%0D%0A * Given a sorted linked list, delete all nodes that have duplicate numbers,%0D%0A * leaving only distinct numbers from the original list.%0D%0A * %0D%0A * For example, Given 1-%3E2-%3E3-%3E3-%3E4-%3E4-%3E5, return 1-%3E2-%3E5. Given 1-%3E1-%3E1-%3E2-%3E3,%0D%0A * return 2-%3E3.%0D%0A * %0D%0A * @author Michael Wan.%0D%0A *%0D%0A */%0D%0Apublic class RemoveDuplicateFromSortedList2 %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 = new ListNode(0);%0D%0A%09%09ListNode resultHead = result;%0D%0A%09%09ListNode checkDup = head;%0D%0A%09%09boolean isRemoveCurrent = false;%0D%0A%09%09while (head.next != null) %7B%0D%0A%09%09%09if (head.val == head.next.val) %7B%0D%0A%09%09%09%09head.next = head.next.next;%0D%0A%09%09%09%09isRemoveCurrent = true;%0D%0A%09%09%09%09continue;%0D%0A%09%09%09%7D%0D%0A%09%09%09if(!isRemoveCurrent)%7B%0D%0A%09%09%09%09result.next = checkDup;%0D%0A%09%09%09%7Delse%7B%0D%0A%09%09%09%09result.next = head.next;%0D%0A%09%09%09%7D%0D%0A%09%09%09result = result.next;%0D%0A%09%09%09checkDup = head.next;%0D%0A%09%09%09isRemoveCurrent = false;%0D%0A%09%09%09head = checkDup;%0D%0A%09%09%09%0D%0A%09%09%7D%0D%0A%0D%0A%09%09return resultHead.next;%0D%0A%09%7D%0D%0A%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(3));%0D%0A%09%09ListNode node5 = (node4.next = new ListNode(6));%0D%0A%09%09ListNode node6 = (node5.next = new ListNode(6));%0D%0A%0D%0A%09%09ListNode recorderList = new RemoveDuplicateFromSortedList2()%0D%0A%09%09%09%09.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

check in not finished.