SOURCE

// 双指针

// [1,2,3,4,5,6,7,8,9,10]

const arr = [1,2,3,4,5,6,7,8,9,10]

function get(arr, count) {
    const arrLength = arr.length
    let startIndex = 0
    let lastIndex = arrLength - 1
    let findIndexArr = []
    while (startIndex < lastIndex) {
        const sum = arr[startIndex] + arr[lastIndex]
        console.log(sum)
        if (sum === count) {
            findIndexArr = [startIndex, lastIndex]
            break
        } 
        if (sum > count) {
            lastIndex--
        }

        if (sum < count) {
            startIndex++
        }
    }

    return findIndexArr
}


console.log(get(arr, 12), '<----get(arr, 10)')
console 命令行工具 X clear

                    
>
console