Skip to content

Instantly share code, notes, and snippets.

@aniruddha84
Last active January 15, 2018 22:34
Show Gist options
  • Save aniruddha84/2dd516e2874294c3b9b2dff149253853 to your computer and use it in GitHub Desktop.
Save aniruddha84/2dd516e2874294c3b9b2dff149253853 to your computer and use it in GitHub Desktop.
Remove duplicates from Sorted Array
// https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/
public void removeDuplicates(int[] arr) {
if (arr.length <= 1) return arr.length;
int p1 = 1;
for(int i = 1; i < arr.length; i++) {
if (arr[i] != arr[i-1]) {
arr[p1] = arr[i];
p1 += 1;
}
}
return p1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment