Skip to content

Commit 5ed99e8

Browse files
author
abc
committed
two sum solution
1 parent 53ce7c7 commit 5ed99e8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

two-sum/SeongA.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
3+
var dictionary: [Int: Int] = [:]
4+
for (index, value) in nums.enumerated() {
5+
let difference = target - value
6+
if let otherIndex = dictionary[difference] {
7+
return [otherIndex, index]
8+
}
9+
dictionary[value] = index
10+
}
11+
return []
12+
}
13+
}

0 commit comments

Comments
 (0)