1. Two Sum

ø202401162158
tags: #hash-map

var twoSum = function(nums, target) {
	const map = new Map();
	for (let i = 0; i < nums.length; i++) {
		if (map.has(target - nums[i])) {
			return [map.get(target - nums[i]), i];
		}
		map.set(nums[i], i);
	}
	return [-1, -1];
};

Reference

https://leetcode.com/problems/two-sum/