@@ -0,0 +1,1213 @@
+package list.lc084_removeduplicatefromsortedlist2;%0A%0Aimport list.ListNode;%0A%0A/**%0A * Given a sorted linked list, delete all nodes that have duplicate numbers,%0A * leaving only distinct numbers from the original list.%0A * For example,%0A * Given 1-%3E2-%3E3-%3E3-%3E4-%3E4-%3E5, return 1-%3E2-%3E5.%0A * Given 1-%3E1-%3E1-%3E2-%3E3, return 2-%3E3.%0A */%0Apublic class Solution %7B%0A    public ListNode deleteDuplicates(ListNode head) %7B%0A        if (head == null) %7B%0A            return head;%0A        %7D%0A%0A        // Sentinel for simplicity%0A        ListNode prev = new ListNode(-1);%0A        prev.next = head;%0A        head = prev;%0A%0A        ListNode cur = head.next;%0A        boolean isDup = false;%0A        while (cur != null) %7B%0A            if (prev.next == cur) %7B%0A                cur = cur.next;%0A                continue;%0A            %7D%0A%0A            if (prev.next.val == cur.val) %7B%0A                isDup = true;%0A            %7D else %7B%0A                if (isDup) %7B%0A                    prev.next = cur;%0A                    isDup = false;%0A                %7D else %7B%0A                    prev = prev.next;%0A                %7D%0A            %7D%0A            cur = cur.next;%0A        %7D%0A%0A        if (isDup) %7B%0A            prev.next = null;%0A        %7D%0A%0A        return head.next;%0A    %7D%0A%7D%0A

leetcode-84 remove duplicates from sorted list2