Last active
January 15, 2018 22:34
-
-
Save aniruddha84/2dd516e2874294c3b9b2dff149253853 to your computer and use it in GitHub Desktop.
Remove duplicates from Sorted Array
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
// 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