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 Desolve/17ad6dbe70bef408aa2c3c40cb00acaf to your computer and use it in GitHub Desktop.
Save Desolve/17ad6dbe70bef408aa2c3c40cb00acaf to your computer and use it in GitHub Desktop.
0026 Remove Duplicates from Sorted Array
class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length <= 1) return nums.length;
int i = 0;
for (int j = 1; j < nums.length; j++) {
if (nums[j] != nums[i]) {
i++;
nums[i] = nums[j];
}
}
return i + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment