1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/swift/two-sum.swift

16 lines
343 B
Swift
Raw Normal View History

class Solution {
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var encountered: [Int: Int] = [:]
for (i, x) in nums.enumerated() {
if encountered[target - x] != nil {
return [encountered[target - x]!, i]
}
encountered[x] = i
}
return []
}
}