Created
January 19, 2022 20:47
-
-
Save MorrisLaw/e6e8aaf31c75e55fa8ca6aaa9e2c4358 to your computer and use it in GitHub Desktop.
two sum O(n^2) solution
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
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