Created
December 15, 2022 23:29
-
-
Save abdulrahmanAlotaibi/130e75a4cc2cb20342b905cdd1dd89a3 to your computer and use it in GitHub Desktop.
Array #8 : Two Sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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