Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/f7156b033b783b3a01c2ad2cb3d1b313 to your computer and use it in GitHub Desktop.
Save jianminchen/f7156b033b783b3a01c2ad2cb3d1b313 to your computer and use it in GitHub Desktop.
Remove duplicate from sorted array - facebook code lab - pass all test cases.
public class Solution {
public int removeDuplicates(List<Integer> a) {
if(a==null || a.size() == 0)
return 0;
int prev = Integer.valueOf(a.get(0));
int index = 0;
int count = 0;
for(int i=1; i< a.size(); i++)
{
int curr = Integer.valueOf(a.get(i));
if(curr != prev)
{
count++;
a.set(count, curr); // set array new value
prev = curr;
}
}
return count +1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment