MCPcopy
hub / github.com/TheAlgorithms/JavaScript / TwoSum

Function TwoSum

Maths/TwoSum.js:15–23  ·  view source on GitHub ↗
(nums, target)

Source from the content-addressed store, hash-verified

13 */
14
15const TwoSum = (nums, target) => {
16 const numIndicesMap = new Map()
17 for (let i = 0; i < nums.length; i++) {
18 const complement = target - nums[i]
19 if (numIndicesMap.has(complement)) return [numIndicesMap.get(complement), i]
20 numIndicesMap.set(nums[i], i)
21 }
22 return []
23}
24export { TwoSum }

Callers 1

TwoSum.test.jsFile · 0.90

Calls 3

hasMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected