Completes 18/22 timed out

This commit is contained in:
Jacob Delgado 2023-08-17 02:00:30 -07:00
parent 976b6174eb
commit c4be189687

View File

@ -1,16 +1,19 @@
from functools import reduce
import operator
def productExceptSelf(nums): def productExceptSelf(nums):
""" """
:type nums: List[int] :type nums: List[int]
:rtype: List[int] :rtype: List[int]
""" """
numsProduct = [] final = []
for x in range(len(nums)): for x in range(len(nums)):
firstHalf = nums[:x] temp = nums[0]
secondHalf = nums[(len(nums)-x):] del nums[0]
if firstHalf: final.append(reduce(operator.mul, nums))
product = firstHalf + secondHalf # print(nums)
numsProduct.append(product) nums.append(temp)
# print(final)
return numsProduct return final
print(productExceptSelf([1,2,3,4])) print(productExceptSelf([1,2,3,4]))