Last active
February 17, 2021 17:31
-
-
Save Roshankumar350/d161320138c2e8c33b229e71811786a3 to your computer and use it in GitHub Desktop.
Day 1 of Advent Code
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 characters
func findIndexOf(targetSum sum: Int, in inputArray: [Int]) -> (Int,Int) { | |
//Output index | |
var indices: (Int,Int) = (-1, -1) | |
//count of input array | |
let inputArrayCount = inputArray.count | |
for (index, eachElement) in inputArray.enumerated() { | |
for sartIndex in index..<inputArrayCount { | |
if eachElement + inputArray[sartIndex] == sum { | |
indices.0 = index | |
indices.1 = sartIndex | |
break | |
} else { | |
continue | |
} | |
} | |
if indices.0 != -1 || indices.1 != -1 { | |
break | |
} | |
} | |
return indices | |
} | |
let indicess = findIndexOf(targetSum: 2020, in: inputArray) | |
print(inputArray[indicess.0] * inputArray[indicess.1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment