Algorithm
LeetCode
자신 제외 모든 곱(틀림)

Product of Array Except Self

문제 Link (opens in a new tab)

해결 방법

class Solution() : 
  def productExceptSelf(self, nums: list[int]) -> list[int] :
    out = []
    p = 1
    for i in range(0, len(nums)) :
      out.append(p) 
      p = p * nums[i]
    p = 1
    for i in range(len(nums) - 1, -1, -1) : 
      out[i] = out[i] * p
      p = p *nums[i]
    return out

해설