Skip to content

Instantly share code, notes, and snippets.

@topeogunleye
Created May 19, 2022 07:33
Show Gist options
  • Save topeogunleye/3aff9a666077d1a46bece80c2e72aaa0 to your computer and use it in GitHub Desktop.
Save topeogunleye/3aff9a666077d1a46bece80c2e72aaa0 to your computer and use it in GitHub Desktop.
Two Sum LeetCode Challenge
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
const twoSums = [0,0];
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
twoSums[0] = i
twoSums[1] = j
}
}
}
return twoSums
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment