Skip to content

Instantly share code, notes, and snippets.

@mumunuu
Last active January 5, 2021 14:30
Show Gist options
  • Save mumunuu/d4b6e278fc1b68e74d425e086ff30d01 to your computer and use it in GitHub Desktop.
Save mumunuu/d4b6e278fc1b68e74d425e086ff30d01 to your computer and use it in GitHub Desktop.
algorithm(leetcode) Remove Duplicates from Sorted Array
func removeDuplicates(nums []int) int {
if len(nums) == 0 {
return 0
}
i := 0
j := 1
for j < len(nums) {
if nums[j] != nums[i] {
i++
nums[i] = nums[j]
j++
} else {
j++
}
}
return i + 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment