Skip to content

Commit 056f941

Browse files
committed
Sync LeetCode submission - Two Sum (golang)
1 parent 921e480 commit 056f941

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

problems/two_sum/solution.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
func twoSum(nums []int, target int) []int {
2+
hash_map := make(map[int]int)
3+
4+
for i:= 0; i < len(nums); i++{
5+
hash_map[nums[i]] = i
6+
}
7+
8+
for i := 0; i < len(nums); i++{
9+
complement := target - nums[i]
10+
if _, found := hash_map[complement]; found{
11+
if hash_map[complement] != i{
12+
return [] int{i, hash_map[complement]}
13+
}
14+
}
15+
}
16+
return nil
17+
}

0 commit comments

Comments
 (0)