Skip to content

Instantly share code, notes, and snippets.

@vicxruiz
Last active April 8, 2020 15:41
Show Gist options
  • Save vicxruiz/35de65476b4ae1a3db5017dbeff11b0f to your computer and use it in GitHub Desktop.
Save vicxruiz/35de65476b4ae1a3db5017dbeff11b0f 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 1:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].
Example 2:
Given nums = [3,2,4], target = 6,
Expected:
[1,2]
Example 3:
Given nums = [3,3], target = 6
Expected:
[0,1]
func sum(_ nums: [Int], _ target: Int) -> [Int] {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment