From 6aa97ff60016ad728deb81e7ecef3b6cae02def8 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Thu, 10 Oct 2019 18:39:29 +0200 Subject: [PATCH] Added solition for #1 in Javascript --- leet_1.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 leet_1.js diff --git a/leet_1.js b/leet_1.js new file mode 100644 index 0000000..cf8b1af --- /dev/null +++ b/leet_1.js @@ -0,0 +1,17 @@ +// https://leetcode.com/problems/two-sum/submissions/ +// Runtime: 112 ms, faster than 37.73% of JavaScript online submissions for Two Sum. + +/** + * @param {number[]} nums + * @param {number} target + * @return {number[]} + */ +var twoSum = function(nums, target) { + for(let i = 0; i < nums.length; i++) { + for(let y = i + 1; y < nums.length; y++) { + if(nums[i] + nums[y] === target) { + return [i, y]; + } + } + } +}; \ No newline at end of file