除自身以外数组的乘积

给你一个长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积。

function productExceptSelf(nums) {
    let arr = []
    for(let i = 0;i < nums.length;i++){
        let sum = 1
        for(let j = 0;j < nums.length;j++){
            let jItem = nums[j]
            if(i != j){
                sum *= jItem 
            }
        }
        arr.push(sum)
    }
    return arr
}

Leecode提交通过

原文地址:https://www.cnblogs.com/zhenjianyu/p/13402789.html