Created
March 24, 2021 13:46
-
-
Save rohanjai777/4c53b70e32310d7e0bb71c11d2cf7beb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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