# https://leetcode.com/problems/product-of-array-except-self/


class Solution:
    def productExceptSelf(self, nums):
        products = []
        products.append(1)
        product = 1
        for num in nums[:-1]:
            product *= num
            products.append(product)
        product = 1
        for index, num in enumerate(reversed(nums[1:])):
            product *= num
            products[-(index + 2)] *= product

        return products


nums = [-1, 1, 0, -3, 3]
# print(nums[1:])
products = Solution().productExceptSelf(nums)
print(products)
# https://leetcode.com/problems/product-of-array-except-self/


class Solution:
    def productExceptSelf(self, nums):
        products = []
        products.append(1)
        product = 1
        for num in nums[:-1]:
            product *= num
            products.append(product)
        product = 1
        for index, num in enumerate(reversed(nums[1:])):
            product *= num
            products[-(index + 2)] *= product

        return products


nums = [-1, 1, 0, -3, 3]
# print(nums[1:])
products = Solution().productExceptSelf(nums)
print(products)
# https://leetcode.com/problems/product-of-array-except-self/ # print(nums[1:])