Skip to content

Instantly share code, notes, and snippets.

@junebash
Created December 11, 2019 16:10
Show Gist options
  • Save junebash/8d953a0dbdbf13817a44c9f1d925e42b to your computer and use it in GitHub Desktop.
Save junebash/8d953a0dbdbf13817a44c9f1d925e42b to your computer and use it in GitHub Desktop.
FindMissingNumbers
func findMissingNumbers(_ nums: [Int]) -> [Int] {
var includedNums = [Int:Int]()
var missingNums = [Int]()
for num in nums {
includedNums[num] = num
}
for i in 1...nums.count {
if includedNums[i] == nil {
missingNums.append(i)
}
}
return missingNums
}
print(findMissingNumbers([4,3,2,7,8,2,3,1]))
print(findMissingNumbers([1,9,9,6,1,2,3,4,5,5,5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment