leetCode #1

#1. Two Sum

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function(nums, target) {
    let map = new Map();
    for(let i in nums) {
        if(map.has(target - nums[i])) {
            return [map.get(target - nums[i]), parseInt(i)]
        }
        map.set(nums[i], parseInt(i))
    }
    console.log("can't find the result")
};

你可能感兴趣的:(leetCode #1)