Algorithms and Data Structures/Coding Practices
AlgoExpert Array of Products
brightlightkim
2022. 7. 22. 09:19
def arrayOfProducts(array):
# Write your code here.
products = 1
zeroIdx = []
for i in range(len(array)):
if (array[i] == 0):
zeroIdx.append(i)
else:
products *= array[i]
for i in range(len(array)):
if len(zeroIdx) > 1:
array[i] = 0
elif len(zeroIdx) == 1:
if i in zeroIdx:
array[i] = products
else:
array[i] = 0
else:
array[i] = products / array[i]
return array