IT/코딩테스트
[Leetcode] 238. Product of Array Except Self
이주디
2024. 3. 15. 21:35
728x90
https://leetcode.com/problems/product-of-array-except-self
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
result = [1] * len(nums)
prifix_value = 1
for i in range(0, len(nums)):
result[i] *= prifix_value
prifix_value *= nums[i]
suffix_value = 1
for i in range(len(nums)-1, -1, -1):
result[i] *= suffix_value
suffix_value *= nums[i]
return result
728x90