2022-09-16 00:34:07 +03:00
|
|
|
package twonums
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var test_nums []int
|
|
|
|
test_nums = append(test_nums, 2, 3, 5, 6, 9, 1)
|
2022-09-16 13:48:36 +03:00
|
|
|
fmt.Print(TwoSum(test_nums, 10))
|
2022-09-16 00:34:07 +03:00
|
|
|
}
|
|
|
|
|
2022-09-16 13:48:36 +03:00
|
|
|
func TwoSum(nums []int, target int) []int {
|
2022-09-16 00:34:07 +03:00
|
|
|
|
|
|
|
var result []int
|
|
|
|
|
|
|
|
for i := 0; i < len(nums); i++ {
|
|
|
|
for j := i + 1; j < len(nums); j++ {
|
|
|
|
if nums[i]+nums[j] == target {
|
|
|
|
result = append(result, i, j)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|