js版 var twoSum = (arr, target) => { let map = new Map(), res = []; arr.forEach((item,index) => { const map_index = map.get(target - item); if(map_index !== undefined){ res = [map_index, index] }else { map.set(item, index) } }); return res; };