Skip to content

Instantly share code, notes, and snippets.

@MorrisLaw
Created January 19, 2022 20:47
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 MorrisLaw/e6e8aaf31c75e55fa8ca6aaa9e2c4358 to your computer and use it in GitHub Desktop.
Save MorrisLaw/e6e8aaf31c75e55fa8ca6aaa9e2c4358 to your computer and use it in GitHub Desktop.
two sum O(n^2) solution
func twoSum(nums []int, target int) []int {
if nums == nil {
return nil
}
for i := 0; i < len(nums); i++ {
for j := i+1; j < len(nums); j++ {
if nums[i] + nums[j] == target {
return []int{i, j}
}
}
}
return []int{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment