Attempt using slicing to achieve O(n) without division.

This commit is contained in:
Jacob Delgado 2023-08-12 09:09:03 -07:00
parent 9e47fadc37
commit c9bdf86fac

View File

@ -1,6 +1,15 @@
def productExceptSelf(self, nums):
def productExceptSelf(nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
numsProduct = []
for x in range(len(nums)):
firstHalf = nums[:x]
secondHalf = nums[(len(nums)-x):]
if firstHalf:
product = firstHalf + secondHalf
numsProduct.append(product)
return numsProduct
print(productExceptSelf([1,2,3,4]))