mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
13 lines
202 B
Go
13 lines
202 B
Go
package leetcode
|
|
|
|
func twoSum(nums []int, target int) []int {
|
|
m := make(map[int]int)
|
|
for k, v := range nums {
|
|
if idx, ok := m[target-v]; ok {
|
|
return []int{idx, k}
|
|
}
|
|
m[v] = k
|
|
}
|
|
return nil
|
|
}
|