Share my accepted Java solution


  • 0
    I
    public int removeDuplicates(int[] A) {
            int length = A.length;
            if (length == 0)  return 0;
            int i = 1, j = 0;
            while (j < length) {
                if (A[j] != A[i-1]) {
                    A[i] = A[j];
                    i++;
                }
                j++;
            }
            return i;
        }

Log in to reply
 

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