Skip to main content

238. Product of Array Except Self - LeetCode

ยท One min read
class Solution:
def productExceptSelf(self, nums: list[int]) -> list[int]:
result = [1] * len(nums)
l = r = 1
for i in range(len(nums)):
result[i] *= l
l *= nums[i]
result[-1 - i] *= r
r *= nums[-1 - i]
return result