@@ -0,0 +1,1516 @@
+/***%0A * Given a sorted linked list, delete all duplicates such that each element appear only once.%0A *%0A * For example,%0A * Given 1-%3E1-%3E2, return 1-%3E2.%0A * Given 1-%3E1-%3E2-%3E3-%3E3, return 1-%3E2-%3E3.%0A */%0A/**%0A * Definition for singly-linked list.%0A * public class ListNode %7B%0A *     int val;%0A *     ListNode next;%0A *     ListNode(int x) %7B%0A *         val = x;%0A *         next = null;%0A *     %7D%0A * %7D%0A*/%0Apublic class RemoveDuplicatesfromSortedList %7B%0A    %0A    // Solution 2:  O(n) O(1)%0A    // Starts from the second Node.%0A    public ListNode deleteDuplicates(ListNode head) %7B%0A        if (head == null)%0A            return head;%0A        int cur = head.val;%0A        ListNode p = head.next;%0A        ListNode prev = head;%0A        while (p != null) %7B%0A            if (p.val == cur) %7B%0A                prev.next = p.next;%0A                p = prev.next;%0A            %7D else %7B%0A                cur = p.val;%0A                prev = prev.next;%0A                p = p.next;%0A            %7D%0A        %7D%0A        return head;%0A    %7D%0A%0A    public static void main (String args%5B%5D) %7B%0A        RemoveDuplicatesfromSortedList rdfsl = new RemoveDuplicatesfromSortedList();%0A        ListNode node1 = new ListNode(1);%0A        ListNode node2 = new ListNode(1);%0A        ListNode node3 = new ListNode(1);%0A        node1.next = node2;%0A        node2.next = node3;%0A%0A        ListNode node = rdfsl.deleteDuplicates(node1);%0A        while (node != null) %7B%0A            System.out.printf(%22%25d%5Ct%22, node.val);%0A            node = node.next;%0A        %7D%0A        System.out.println();%0A    %7D%0A%7D%0A

add RemoveDuplicatesfromSortedList.java