package com.fishercoder.solutions;

import com.fishercoder.common.classes.ListNode;

/**
 * 82. Remove Duplicates from Sorted List II
 *
 *  Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

 For example,
 Given 1->2->3->3->4->4->5, return 1->2->5.
 Given 1->1->1->2->3, return 2->3.

 */
public class _82 {
  public static class Solution1 {
    public ListNode deleteDuplicates(ListNode head) {
      if (head == null) {
        return head;
      }
      ListNode fakeHead = new ListNode(-1);
      fakeHead.next = head;
      ListNode pre = fakeHead;
      ListNode curr = head;
      while (curr != null) {
        while (curr.next != null && curr.val == curr.next.val) {
          curr = curr.next;
        }
        if (pre.next == curr) {
          pre = pre.next;
        } else {
          pre.next = curr.next;
        }
        curr = curr.next;
      }
      return fakeHead.next;
    }
  }

}

@@ -82,291 +82,8 @@
 e;%0A%0A
-/**%0A * 82. Remove Duplicates from Sorted List II%0A *%0A *  Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.%0A%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%0A */%0A
 publ
@@ -97,16 +97,18 @@
 s _82 %7B%0A
+  
   public
@@ -133,24 +133,28 @@
 tion1 %7B%0A    
+  
+  
 public ListN
@@ -187,24 +187,30 @@
 ode head) %7B%0A
+      
       if (he
@@ -227,24 +227,32 @@
 ) %7B%0A        
+     
+   
 return head;
@@ -258,24 +258,36 @@
 ;%0A      
-%7D%0A
+      %7D%0A     
       
+ 
 ListNode
@@ -316,16 +316,22 @@
 de(-1);%0A
+      
       fa
@@ -346,24 +346,30 @@
 ext = head;%0A
+      
       ListNo
@@ -383,24 +383,30 @@
 = fakeHead;%0A
+      
       ListNo
@@ -423,24 +423,30 @@
 head;%0A      
+ 
+     
 while (curr 
@@ -456,32 +456,40 @@
 null) %7B%0A        
+  
+      
 while (curr.next
@@ -531,32 +531,42 @@
 al) %7B%0A          
+       
+   
 curr = curr.next
@@ -575,26 +575,37 @@
         
-%7D%0A
+        %7D%0A   
         
 if (pre.
@@ -592,24 +592,29 @@
 %0A           
+     
 if (pre.next
@@ -635,16 +635,26 @@
         
+        
+  
 pre = pr
@@ -657,24 +657,32 @@
 = pre.next;%0A
+        
         %7D el
@@ -696,16 +696,26 @@
         
+    
+      
 pre.next
@@ -728,34 +728,50 @@
 r.next;%0A        
+       
+ 
 %7D%0A
+        
         curr = c
@@ -782,26 +782,38 @@
 next;%0A      
+     
+ 
 %7D%0A
+      
       return
@@ -832,17 +832,23 @@
 xt;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%0A%7D%0A

refactor 82