📜  javascript 函数,for 循环,线性时间复杂度 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:20.235000             🧑  作者: Mango

代码示例1
function crossAdd(input) {
    var answer = [];
    for (var i = 0; i < input.length; i++) {
        var goingUp = input[i];
        var goingDown = input[input.length-1-i];
        answer.push(goingUp + goingDown);
    }
    return answer;
}
// O(N) time complexity