238. Product of Array Except Self π₯
Medium
Problem:
Input: nums = [1,2,3,4]
Output: [24,12,8,6]Solution:
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
answer = []
result = 1
for idx, num in enumerate(nums):
answer.append(result)
result *= num
result = 1
for i in range(len(nums) - 1, -1, -1):
answer[i] *= result
result *= nums[i]
return answerLast updated