Accepted remove duplicates from sorted array java solution


  • 0
    V

    public class Solution {

    public int removeDuplicates(int[] A) {
    
        if(A == null){
            return 0;
        }
        
        int j = 0;
        int len = A.length;
    
        for(int i = 1; i < A.length; i++){
            if(A[j] == A[i]){
                len--;
                continue;
            }else{
                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.