Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MARK: - TWO SUMM
- func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
- var dict = [Int:Int]()
- for (index, num) in nums.enumerated() {
- let dif = target - num
- if dict[dif] != nil {
- return [dict[dif]!, index]
- }
- if dict[dif] == nil {
- dict[num] = index
- }
- }
- return []
- }
- //twoSum([2,7,11,15], 9)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement