版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412903
思路
从两端向中间遍历
code
代码语言:javascript复制func twoSum(numbers []int, target int) []int {
l, r := 0, len(numbers)-1
for l < r {
if numbers[l] numbers[r] < target {
l
} else if numbers[l] numbers[r] > target {
r--
} else {
return []int{l 1, r 1}
}
}
return nil
}