Skip to content

Commit c2d3a44

Browse files
committed
golang solution
1 parent f9eba58 commit c2d3a44

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func twoSum(nums []int, target int) []int {
2+
m := make(map[int]int)
3+
for i, v := range nums {
4+
if _, ok := m[v]; ok && v**2 == target {
5+
return []int{i, m[v]}
6+
}
7+
m[v] = i
8+
}
9+
for k, v1 := range m {
10+
if v2, ok := m[target-k]; v1 != v2 && ok {
11+
return []int{v1, v2}
12+
}
13+
}
14+
return []int{}
15+
}
16+

0 commit comments

Comments
 (0)