Created
May 10, 2016 18:44
-
-
Save vikmeup/b7331114ec2d9e6f3043c8b11d6d5102 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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