LEETCODE - Product of Array Except Self

Coaspe·2021년 7월 3일
0

Algorithm-배열

목록 보기
7/8
post-thumbnail

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 * out[i]
    return out
profile
https://github.com/Coaspe

0개의 댓글