This commit is contained in:
Gleb Koval 2021-11-05 12:52:26 +00:00
parent cc79df656f
commit 8c338a768f
No known key found for this signature in database
GPG Key ID: 7C89CDC822F8392B
1 changed files with 14 additions and 0 deletions

14
two-sum/sol.go Normal file
View File

@ -0,0 +1,14 @@
package main
// Time: O(n)
// Space: O(n)
func twoSum(nums []int, target int) []int {
exists := make(map[int]int)
for i1, num := range nums {
if i2, ok := exists[target-num]; ok && i1 != i2 {
return []int{i1, i2}
}
exists[num] = i1
}
return []int{}
}