Remove from sorted array ii java solution


  • 0
    V

    public class Solution {

    public int removeDuplicates(int[] A) {
    
        if(A == null){
            return 0;
        }
        
        int j = 0;
        int count = 0;
        int len = A.length;
        
        for(int i = 1; i < A.length; i++){
            if(A[i] == A[j]){
                count++;
                if(count >= 2){
                    //j++;
                    len--;
                }else{
                    j++;
                    A[j] = A[i];
                }
            }else{
                count = 0;
                j++;
                A[j] = A[i];
            }
        }
        
        return len;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.