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):
"""
:type nums: List[int]
:rtype: List[int]
"""
numsProduct = []
final = []
for x in range(len(nums)):
firstHalf = nums[:x]
secondHalf = nums[(len(nums)-x):]
if firstHalf:
product = firstHalf + secondHalf
numsProduct.append(product)
return numsProduct
temp = nums[0]
del nums[0]
final.append(reduce(operator.mul, nums))
# print(nums)
nums.append(temp)
# print(final)
return final
print(productExceptSelf([1,2,3,4]))