【数组】构建乘积数组
2019-10-10 本文已影响0人
一个想当大佬的菜鸡
# -*- coding:utf-8 -*-
class Solution:
def multiply(self, A):
# write code here
tempA = [1 for _ in range(len(A))]
tempB = [1 for _ in range(len(A))]
for i in range(1, len(A)):
tempA[i] = tempA[i-1] * A[i-1]
for i in range(len(A)-2, -1, -1):
tempB[i] = tempB[i+1] * A[i+1]
for i in range(len(A)):
tempA[i] = tempA[i] * tempB[i]
return tempA