Swift 5 | Better than 98% of solutions
class Solution {
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var map: [Int : Int] = [:]
for (index, num) in nums.enumerated() {
if let res = map[target - num] { return [res, index] }
map[num] = index
}
return []
}
}