@@ -0,0 +1,1647 @@
+/**%0A *%09Follow up for %22Remove Duplicates%22:%0A *%09What if duplicates are allowed at most twice?%0A *%0A *%09For example,%0A *%09Given sorted array nums = %5B1,1,1,2,2,3%5D,%0A *%0A *%09Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3.%0A *%09It doesn't matter what you leave beyond the new length.%0A *%09%0A *%09Author: matao%0A *%0A */%0A%0Apublic class RemoveDuplicatesFromSortedArrayII %7B%0A%09public static int removeDuplicates(int%5B%5D nums) %7B%0A        if(nums == null %7C%7C nums.length == 0) %7B%0A        %09return 0;%0A        %7D%0A%0A        int cur = 0;%0A        int i ,j;%0A        for(i = 0; i %3C nums.length;)%7B%0A            int now = nums%5Bi%5D;%0A            for( j = i; j %3C nums.length; j++)%7B%0A                if(nums%5Bj%5D != now)%0A                    break;%0A                if(j-i %3C 2)%0A                    nums%5Bcur++%5D = now; %0A            %7D%0A            i = j;%0A        %7D%0A        return cur;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09int%5B%5D nums1 = %7B1, 1, 2%7D;%0A    %09System.out.println(removeDuplicates(nums1));%0A%0A    %09int%5B%5D nums2 = %7B1%7D;%0A    %09System.out.println(removeDuplicates(nums2));%0A%0A    %09int%5B%5D nums3 = %7B1, 1, 2, 2%7D;%0A    %09System.out.println(removeDuplicates(nums3));%0A%0A    %09int%5B%5D nums4 = %7B1, 1, 2, 2, 2, 3%7D;%0A    %09System.out.println(removeDuplicates(nums4));%0A%0A    %09int%5B%5D nums5 = %7B-14,-14,-13,-13,-13,-13,-13,-13,-13,-12,-12,-12,-12,-11,-10,-9,-9,-9,-8,-7,-5,-5,-5,-5,-4,-3,-3,-2,-2,-2,-2,-1,-1,-1,-1,-1,0,1,1,1,1,2,2,2,3,3,3,4,4,4,4,5,5,5,6,6,6,6,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,14,14,14,14,15,16,16,16,18,18,18,19,19,19,19,20,20,20,21,21,21,21,21,21,22,22,22,22,22,23,23,24,25,25%7D;%0A    %09System.out.println(removeDuplicates(nums5));%0A    %7D%0A%7D

add Remove Duplicates From Sorted Array solution