package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;

/**
 * 80. Remove Duplicates from Sorted Array II
 *
 * Follow up for "Remove Duplicates":
 What if duplicates are allowed at most twice?

 For example,
 Given sorted array nums = [1,1,1,2,2,3],

 Your function should return length = 5,
 with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn't matter what you leave beyond the new length.
 */
public class _80 {

  public static class Solution1 {
    public int removeDuplicates(int[] nums) {
      int counter = 0;
      int len = nums.length;
      if (len == 0) {
        return 0;
      }
      if (len == 1) {
        return 1;
      }
      if (len == 2) {
        return 2;
      }

      List<Integer> a = new ArrayList();
      a.add(nums[0]);
      a.add(nums[1]);
      for (int i = 2; i < len; i++) {
        if (nums[i] != nums[i - 1]) {
          a.add(nums[i]);
        } else if (nums[i] != nums[i - 2]) {
          a.add(nums[i]);
        }
      }

      counter = a.size();
      for (int i = 0; i < counter; i++) {
        nums[i] = a.get(i);
      }
      return counter;
    }
  }

}

@@ -85,367 +85,8 @@
 t;%0A%0A
-/**%0A * 80. Remove Duplicates from Sorted Array II%0A *%0A * Follow up for %22Remove Duplicates%22:%0A What if duplicates are allowed at most twice?%0A%0A For example,%0A Given sorted array nums = %5B1,1,1,2,2,3%5D,%0A%0A Your function should return length = 5,%0A with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn't matter what you leave beyond the new length.%0A */%0A
 publ
@@ -101,16 +101,18 @@
  _80 %7B%0A%0A
+  
   public
@@ -137,16 +137,20 @@
 tion1 %7B%0A
+    
     publ
@@ -189,24 +189,30 @@
 ms) %7B%0A      
+     
+ 
 int counter 
@@ -212,24 +212,30 @@
 ounter = 0;%0A
+      
       int le
@@ -253,24 +253,30 @@
 ngth;%0A      
+ 
+     
 if (len == 0
@@ -283,24 +283,32 @@
 ) %7B%0A        
+    
+    
 return 0;%0A  
@@ -303,34 +303,46 @@
 return 0;%0A      
+    
-%7D%0A
+  %7D%0A      
       if (len ==
@@ -343,24 +343,32 @@
 len == 1) %7B%0A
+        
         retu
@@ -375,26 +375,38 @@
 rn 1;%0A      
+ 
-%7D%0A
+     %7D%0A      
       if (le
@@ -419,24 +419,32 @@
 ) %7B%0A        
+       
+ 
 return 2;%0A  
@@ -443,27 +443,39 @@
 rn 2;%0A      
-%7D%0A%0A
+      %7D%0A%0A      
       List%3CI
@@ -501,32 +501,38 @@
 ayList();%0A      
+    
+  
 a.add(nums%5B0%5D);%0A
@@ -533,24 +533,30 @@
 %5B0%5D);%0A      
+   
+   
 a.add(nums%5B1
@@ -557,32 +557,38 @@
 nums%5B1%5D);%0A      
+ 
+     
 for (int i = 2; 
@@ -607,24 +607,32 @@
 ) %7B%0A        
+   
+     
 if (nums%5Bi%5D 
@@ -645,24 +645,34 @@
 s%5Bi - 1%5D) %7B%0A
+          
           a.
@@ -693,16 +693,24 @@
         
+  
+      
 %7D else i
@@ -734,24 +734,34 @@
 s%5Bi - 2%5D) %7B%0A
+          
           a.
@@ -786,25 +786,45 @@
     
+ 
-%7D%0A      %7D%0A%0A
+       %7D%0A            %7D%0A%0A    
       
+  
 coun
@@ -835,24 +835,30 @@
 = a.size();%0A
+      
       for (i
@@ -895,16 +895,24 @@
         
+ 
+       
 nums%5Bi%5D 
@@ -925,26 +925,38 @@
 t(i);%0A      
+ 
-%7D%0A
+     %7D%0A      
       return
@@ -969,17 +969,23 @@
 er;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%0A%7D%0A

refactor 80