My Java Solution


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

    }


Log in to reply
 

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