Skip to content

Instantly share code, notes, and snippets.

@spurscho
Created December 16, 2019 11:15
Show Gist options
  • Save spurscho/50f215d465c8cccd289d053f14cc5cbc to your computer and use it in GitHub Desktop.
Save spurscho/50f215d465c8cccd289d053f14cc5cbc to your computer and use it in GitHub Desktop.
Leetcode 1. TwoSum
class Solution {
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var arrRes: [Int] = []
var res: Int = 0
for i in 0..<nums.count-1 {
for j in i+1..<nums.count {
if (nums[i] + nums[j]) == target {
arrRes.append(i)
arrRes.append(j)
return arrRes
}
}
}
return arrRes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment