@@ -0,0 +1,1856 @@
+package leetcode;%0A%0A/**%0A * https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/%0A */%0Apublic class Problem82 %7B%0A    public static class ListNode %7B%0A        int val;%0A        ListNode next;%0A%0A        ListNode(int x) %7B%0A            val = x;%0A            next = null;%0A        %7D%0A    %7D%0A%0A    public ListNode deleteDuplicates(ListNode head) %7B%0A        if (head == null) %7B%0A            return null;%0A        %7D%0A        if (head.next == null) %7B%0A            return head;%0A        %7D%0A        ListNode prev = null;%0A        ListNode toBeDeleted = null;%0A        ListNode safe = null;%0A        ListNode newHead = head;%0A        for (ListNode n = head; n != null; n = n.next) %7B%0A            if (toBeDeleted != null) %7B%0A                if (toBeDeleted.val == n.val) %7B%0A                    continue;%0A                %7D else %7B%0A                    if (newHead.val == toBeDeleted.val) %7B%0A                        newHead = n;%0A                    %7D%0A                    if (safe != null) %7B%0A                        safe.next = n;%0A                    %7D else %7B%0A                        // this is for the case like 1 -%3E 1 -%3E 2%0A                        if (n.next == null) %7B%0A                            return n;%0A                        %7D%0A                    %7D%0A                    prev = null;%0A                    toBeDeleted = null;%0A                %7D%0A            %7D%0A            if (prev != null) %7B%0A                if (prev.val == n.val) %7B%0A                    toBeDeleted = prev;%0A                    continue;%0A                %7D else %7B%0A                    safe = prev;%0A                %7D%0A            %7D%0A            prev = n;%0A        %7D%0A        if (safe == null) %7B%0A            return null;%0A        %7D%0A        // there might still be some nodes to be removed%0A        if (toBeDeleted != null && prev.val == toBeDeleted.val) %7B%0A            safe.next = null;%0A        %7D%0A        return newHead;%0A    %7D%0A%7D%0A

Solve problem 82