Attempt using slicing to achieve O(n) without division.
This commit is contained in:
parent
9e47fadc37
commit
c9bdf86fac
@ -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]))
|
||||
Loading…
Reference in New Issue
Block a user