Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rohanjai777/4c53b70e32310d7e0bb71c11d2cf7beb to your computer and use it in GitHub Desktop.
Save rohanjai777/4c53b70e32310d7e0bb71c11d2cf7beb to your computer and use it in GitHub Desktop.
public class Solution {
public int removeDuplicates(ArrayList<Integer> a) {
int j=0;
int n = a.size();
int count = 1;
for(int i=1;i<n;i++){
int v1 = a.get(i);
int v2 = a.get(j);
if(v1!=v2){
count = 1;
j++;
Collections.swap(a,i,j);
}else if(v1 == v2 && count<=1){
count++;
j++;
Collections.swap(a,i,j);
}else{
count++;
}
}
return j+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment