My Java solution


  • 0
    J
    public class Solution {
        public int removeDuplicates(int[] A) {
            if(A.length == 0 || A == null) return 0;
           // if(A.length ==2) return 2;
            if(A.length ==1) return 1;
            
            int buf=0;
            int count=2;
            
            for(int i=2;i<A.length;i++){
                buf = A[count-2];
                if(A[i] != buf){
                    A[count] = A[i];
                    count++;
                }
            }
            return count;
        }
    }

Log in to reply
 

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