Skip to content

Instantly share code, notes, and snippets.

@visualjeff
Created August 3, 2020 18:00
Show Gist options
  • Save visualjeff/311e6ebb651e4ca4344aa898fd978832 to your computer and use it in GitHub Desktop.
Save visualjeff/311e6ebb651e4ca4344aa898fd978832 to your computer and use it in GitHub Desktop.
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.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
Using Nodejs or in a Browser console you could start with this signature:
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
//Put your implementation code here...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment