Skip to content

Instantly share code, notes, and snippets.

@vniche
Created October 20, 2023 21:34
Show Gist options
  • Save vniche/1bc6faefe6c79096ba86fd9c9409deb5 to your computer and use it in GitHub Desktop.
Save vniche/1bc6faefe6c79096ba86fd9c9409deb5 to your computer and use it in GitHub Desktop.
2sum leetcode challenge
func twoSum(nums []int, target int) []int {
for index, number := range nums {
if index == len(nums)-1 {
break
}
for secondIndex, secondNum := range nums[index+1:] {
if number + secondNum == target {
return []int{index, (index+1)+secondIndex}
}
}
}
return []int{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment