题目描述
方法:
正向遍历+反向遍历储存两边的乘积
class Solution:
def constructArr(self, a: List[int]) -> List[int]:
store = []
for i, num in enumerate(a):
if len(store) == 0:
store.append(num)
else:
store.append(store[i-1]*num)
tmp = 1
b = []
n = len(a)
for i in range(len(a)-1,-1,-1):
if i == 0:
b.append(tmp)
else:
b.append(store[i-1] * tmp)
tmp *= a[i]
return b[::-1]