MCPcopy Create free account
hub / github.com/algorithm004-01/algorithm004-01 / Map

Method Map

Week 02/id_171/TwoSumSol.cs:26–45  ·  view source on GitHub ↗

使用字典,字典key为数组中的元素,value为该元素在字典中的索引。 在遍历数组的时候,去字典中看是否有一个key,它的值正好是target - nums[i], 如果存在,则正好是num[i] + key = target,此时就找到了两个和是target的数,返回它们的索引。

(int[] nums, in int target)

Source from the content-addressed store, hash-verified

source not stored for this graph (policy: none)

Callers

nothing calls this directly

Calls 1

AddMethod · 0.80

Tested by

no test coverage detected