My accepted fast and costless Java solution(Easy understanding)


  • 0

    Here is my code:

    public class Solution {
        public int removeDuplicates(int[] A) {
            if(A.length == 0){
                return 0;
            }
            
            int dupliCount = 0;
            int checkNum = A[0];
            for(int i = 1; i < A.length; i++){
                if(A[i] == checkNum){
                    dupliCount++;
                    continue;
                }
                A[i - dupliCount] = A[i];
                checkNum = A[i]; 
            }
            return A.length - dupliCount;
            
        }
    }

Log in to reply
 

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