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 vikmeup/b7331114ec2d9e6f3043c8b11d6d5102 to your computer and use it in GitHub Desktop.
Save vikmeup/b7331114ec2d9e6f3043c8b11d6d5102 to your computer and use it in GitHub Desktop.
func removeDuplicates(inout nums: [Int]) -> Int {
var dict = Dictionary<Int,Int>()
var repeatedCount = 0
for i in 0..<nums.count {
let curIndex = i-repeatedCount
let v = nums[curIndex]
if let value = dict[v] {
dict[v] = value + 1
if (value > 1) {
repeatedCount += 1
nums.removeAtIndex(curIndex)
}
} else {
dict[v] = 1
}
}
return nums.count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment