Last active
February 26, 2020 16:45
-
-
Save froggomad/e37837bebdd13ef7372e0062688955d7 to your computer and use it in GitHub Desktop.
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 findDisappearedNumbers(_ nums: inout [Int]) -> [Int] { | |
var outputArr = [Int]() | |
let numsCount = nums.count | |
guard let minNum = nums.min(), | |
let maxNum = nums.max() | |
else { return [] } | |
let range = minNum...maxNum | |
if numsCount == range.count { | |
return [] | |
} | |
for (index, rangeNum) in range.enumerated() { | |
if index < nums.count { | |
print("rangeNum:", rangeNum) | |
print("nums at index:", nums[index]) | |
if rangeNum != nums[index] { | |
nums.insert(rangeNum, at: index) | |
print("new nums at index:", nums[index]) | |
print("nums at index +1:", nums[index + 1]) | |
outputArr.append(rangeNum) | |
} | |
} | |
} | |
return outputArr | |
} | |
var numsToTest = [1,2,3,5,6,8] | |
findDisappearedNumbers(&numsToTest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment