[Algorithm] 37 week(10.10 ~ 10.16) 3/3

Dev_min·2022년 10월 12일
0

algorithm

목록 보기
122/157

238. Product of Array Except Self

var productExceptSelf = function(nums) {
    const result = [];
    let left = 1;

    for(let i = 0; i < nums.length; i++){
        result.push(left);
        left = left * nums[i];
    }

    let right = 1;
    for(let i = nums.length - 1; i >= 0; i--){
        result[i] = result[i] * right;
        right = right * nums[i]
    }

    return result;
};
profile
TIL record

0개의 댓글