1 parent e38aa8f commit 942d2e8Copy full SHA for 942d2e8
1 file changed
0001-two-sum/0001-two-sum.swift
@@ -0,0 +1,16 @@
1
+class Solution {
2
+ func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
3
+ var result: [Int] = []
4
+ for i in 0..<nums.count {
5
+ guard (i + 1) < nums.count else { break }
6
+ for j in (i + 1)..<nums.count {
7
+ if nums[i] + nums[j] == target {
8
+ result = [i, j]
9
+ break
10
+ }
11
12
+ if !result.isEmpty { break }
13
14
+ return result
15
16
+}
0 commit comments