We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53ce7c7 commit 5ed99e8Copy full SHA for 5ed99e8
two-sum/SeongA.swift
@@ -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