mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2026-03-12 21:01:08 +00:00
添加Go语言题解
This commit is contained in:
@@ -202,3 +202,20 @@ class Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Go Code:
|
||||
|
||||
```go
|
||||
func twoSum(nums []int, target int) []int {
|
||||
m := make(map[int]int)
|
||||
for i, num := range nums {
|
||||
if v, ok := m[target - num]; ok {
|
||||
return []int{v, i}
|
||||
}
|
||||
m[num] = i
|
||||
}
|
||||
return []int{}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user