Python Interview Questions And Answers - Two Sum

preview_player
Показать описание
---- Leetcode Two Sum ----

Given an array of integers,
return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution,
and you may not use the same element twice.
Рекомендации по теме
Комментарии
Автор

蛋老师 说洋文。今天用JS 写的
var twoSum = function(nums, target) {
const comp = {};
const len = nums.length;
for (let i = 0; i < len; i++) {
if {
return [comp[nums[i]], i];
}
const save = target - nums[i];
comp[save] = i;
}
};

eguoli
join shbcf.ru