剑指 Offer II 006. 排序数组中两个数字之和
2022-04-07 本文已影响0人
邦_
双指针 左右指针 因为数组是升序数组
func twoSum(_ numbers: [Int], _ target: Int) -> [Int] {
var head = 0
var end = numbers.count - 1
while true {
if numbers[head] + numbers[end] > target {
end -= 1
}
else if numbers[head] + numbers[end] < target {
head += 1
}
else if numbers[head] + numbers[end] == target {
return [head,end]
}
}
}