Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save spurscho/9652cbb2e4c3d9f6689b4c2f05fbd92e to your computer and use it in GitHub Desktop.

Select an option

Save spurscho/9652cbb2e4c3d9f6689b4c2f05fbd92e to your computer and use it in GitHub Desktop.
26. Remove Duplicates from Sorted Array
class Solution {
func removeDuplicates(_ nums: inout [Int]) -> Int {
guard nums.count > 0 else {
return 0
}
nums.sort()
var idx: Int = 0
while true {
if idx + 1 == nums.count {
break
}
if nums[idx] == nums[idx+1] {
nums.remove(at: idx)
} else {
idx += 1
}
}
return nums.count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment