package com.fishercoder.solutions;

import com.fishercoder.common.classes.ListNode;

/**
 * 83. Remove Duplicates from Sorted List
 *
 * Given a sorted linked list, delete all duplicates such that each element appear only once.

 For example,
 Given 1->1->2, return 1->2.
 Given 1->1->2->3->3, return 1->2->3.
 */
public class _83 {
  public static class Solution1 {
    public ListNode deleteDuplicates(ListNode head) {
      ListNode ret = new ListNode(-1);
      ret.next = head;
      while (head != null) {
        while (head.next != null && head.next.val == head.val) {
          head.next = head.next.next;
        }
        head = head.next;
      }
      return ret.next;
    }
  }

  public static class Solution2 {
    public ListNode deleteDuplicates(ListNode head) {
      ListNode curr = head;
      while (curr != null && curr.next != null) {
        if (curr.val == curr.next.val) {
          curr.next = curr.next.next;
        } else {
          curr = curr.next;
        }
      }
      return head;
    }
  }
}

@@ -82,237 +82,8 @@
 e;%0A%0A
-/**%0A * 83. Remove Duplicates from Sorted List%0A *%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
 publ
@@ -97,16 +97,18 @@
 s _83 %7B%0A
+  
   public
@@ -133,16 +133,20 @@
 tion1 %7B%0A
+    
     publ
@@ -183,32 +183,38 @@
 istNode head) %7B%0A
+      
       ListNode r
@@ -236,16 +236,22 @@
 de(-1);%0A
+      
       re
@@ -257,32 +257,38 @@
 et.next = head;%0A
+      
       while (hea
@@ -292,32 +292,40 @@
 head != null) %7B%0A
+        
         while (h
@@ -379,24 +379,34 @@
 %7B%0A          
+    
+      
 head.next = 
@@ -425,26 +425,42 @@
 xt;%0A        
+      
-%7D%0A
+  %7D%0A        
         head
@@ -475,26 +475,38 @@
 next;%0A      
+  
-%7D%0A
+    %7D%0A      
       return
@@ -524,15 +524,23 @@
     
+  
+  
 %7D%0A  
+ 
+ 
 %7D%0A%0A
+  
   pu
@@ -569,16 +569,20 @@
 tion2 %7B%0A
+    
     publ
@@ -629,24 +629,30 @@
 ad) %7B%0A      
+  
+    
 ListNode cur
@@ -657,24 +657,30 @@
 urr = head;%0A
+      
       while 
@@ -725,16 +725,24 @@
         
+  
+      
 if (curr
@@ -772,24 +772,34 @@
 %7B%0A          
+      
+    
 curr.next = 
@@ -806,32 +806,40 @@
 curr.next.next;%0A
+        
         %7D else %7B
@@ -839,16 +839,26 @@
  else %7B%0A
+          
         
@@ -889,18 +889,32 @@
     
+  
-%7D%0A
+      %7D%0A      
       %7D%0A
     
@@ -905,24 +905,30 @@
           %7D%0A
+      
       return
@@ -938,16 +938,22 @@
 ad;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 83