mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-19 12:36:28 +08:00
14 lines
250 B
Go
14 lines
250 B
Go
package leetcode
|
|
|
|
func twoSum(nums []int, target int) []int {
|
|
m := make(map[int]int)
|
|
for i := 0; i < len(nums); i++ {
|
|
another := target - nums[i]
|
|
if _, ok := m[another]; ok {
|
|
return []int{m[another], i}
|
|
}
|
|
m[nums[i]] = i
|
|
}
|
|
return nil
|
|
}
|