Created
November 13, 2019 16:18
-
-
Save junebash/10b8506ab18cf5aedfd21fb95435fb79 to your computer and use it in GitHub Desktop.
Revisions
-
Jon Bash created this gist
Nov 13, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ func indicesToSum(from array: [Int], to target: Int) -> [Int] { for i in 1 ..< array.count { for j in 0 ..< i { if array[i] + array[j] == target { return [j,i] } } } print("ERROR: No sum possible!") return [] } indicesToSum(from: [2,7,11,15], to: 9) indicesToSum(from: [3,2,4], to: 6) indicesToSum(from: [3,3], to: 6) indicesToSum(from: [9,3,6,23,78,2,45,123,6,17], to: 140)