26. Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Solution
public class Solution {
public int removeDuplicates(int[] A) {
if(A.length < 2) return A.length;
int i = 0;
int j = 1;
for(; j < A.length; j ++){
if(A[j] != A[i])
A[++i] = A[j];
}
return i + 1;
}
}Last updated