80. Remove Duplicates from Sorted Array II

    /*
     * 80. Remove Duplicates from Sorted Array II
     * 2016-5-13 by Mingyang
     * 这里用了通式,就是k的值可以根据需要随时改变,注意这里++j的用法,最后return ++j
     * 注意的是题目不光要返回int,还要把array给换了
     */
     public int removeDuplicates2(int[] A,int k){
            int len=A.length;
            if(len<k)
                return len;
            int j=0;
            int count=1;
            for(int i=1;i<len;i++){
                if(A[i]!=A[i-1]){
                    count=1;
                    A[++j]=A[i];
                }else{
                    if(count<k){
                        A[++j]=A[i];
                        count++;
                    }
                    //大于等于k的基本不用管了
                }
            }
            return ++j;            
        }
原文地址:https://www.cnblogs.com/zmyvszk/p/5494027.html