Skip to content

Instantly share code, notes, and snippets.

@abdulrahmanAlotaibi
Created December 15, 2022 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulrahmanAlotaibi/130e75a4cc2cb20342b905cdd1dd89a3 to your computer and use it in GitHub Desktop.
Save abdulrahmanAlotaibi/130e75a4cc2cb20342b905cdd1dd89a3 to your computer and use it in GitHub Desktop.
Array #8 : Two Sum
/*
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
*/
func twoSum(nums []int, target int) []int {
var indices []int
for i:=0 ; i < len(nums) ; i++ {
for j:=i+1; j < len(nums);j++ {
if nums[j] + nums[i] == target {
indices = []int{i,j}
}
}
}
return indices
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment