Open fockspaces opened 1 year ago
GPT improve:
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
results = [1] * len(nums)
right_prod = 1
for i in range(1, len(nums)):
results[i] = results[i - 1] * nums[i - 1]
for i in reversed(range(len(nums))):
results[i] *= right_prod
right_prod *= nums[i]
return results