Created
December 11, 2019 16:10
-
-
Save junebash/8d953a0dbdbf13817a44c9f1d925e42b to your computer and use it in GitHub Desktop.
FindMissingNumbers
This file contains 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 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