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 8415ff6 commit 30f5aaeCopy full SHA for 30f5aae
two-sum/doitduri.swift
@@ -0,0 +1,16 @@
1
+class Solution {
2
+ func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
3
+ let dict = nums.enumerated().reduce(into: [Int: Int]()) { initialValue, num in
4
+ initialValue[num.element] = num.offset
5
+ }
6
+
7
+ for startIndex in 0..<nums.count {
8
+ let findValue = target - nums[startIndex]
9
+ if let endIndex = dict[findValue], startIndex != endIndex {
10
+ return [startIndex, endIndex]
11
12
13
14
+ return []
15
16
+}
0 commit comments