Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 307 Bytes

两数之和.md

File metadata and controls

19 lines (14 loc) · 307 Bytes
function twoSum(nums, target) {
  let map = new Map();

  for (let i = 0; i < nums.length; i++) {
    let k = target - nums[i];

    if (map.has(k)) {
      return [map.get(k), i];
    }

    map.set(nums[i], i);
  }

  return [];
}