Accepted simple Java Solution


  • 0
    W
    public class Solution {
        public int removeDuplicates(int[] A) {
            
            if(A.length == 0)return 0;
            if(A.length == 1)return 1;
            
            int count = 0;
            
            for(int i=1; i<A.length; ++i){
                
                if(A[i]==A[i-1])count++;
                else A[i-count] = A[i];
            }
            return A.length - count;
        }
    }

Log in to reply
 

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