MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / twoSum

Function twoSum

tasks/1.go:7–18  ·  view source on GitHub ↗
(nums []int, target int)

Source from the content-addressed store, hash-verified

5}
6
7func twoSum(nums []int, target int) []int {
8 // [rem]ind
9 remMap := make(map[int]int)
10 for i, v := range nums {
11 if val, ok := remMap[v]; ok {
12 return []int{val, i}
13 }
14 rem := target - v
15 remMap[rem] = i
16 }
17 return []int{-1, -1}
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected