Created
November 13, 2019 16:36
-
-
Save RoastBeefKazenakis/81f91a359131bbde74aa2229a4b8512c to your computer and use it in GitHub Desktop.
Sum CodeChallenge 11/13/19 by: Thomas Sabino-Benowitz
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 sum(_ nums: [Int], _ target: Int) -> [Int] { | |
var sumIndex: [Int] = [] | |
for x in 0..<target { | |
for y in 0...x{ | |
if (nums.firstIndex(of: x) != nil) { | |
if (nums.firstIndex(of: y) != nil) { | |
if x + y == target { | |
sumIndex.append(nums.firstIndex(of: y)!) | |
sumIndex.append(nums.firstIndex(of: x)!) | |
} | |
} | |
} | |
} | |
} | |
return sumIndex | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment