'''
除了数字本身的其它数累乘,替换本身数字
'''
class Solution:
def productExcludeItself(self, nums):
nums_size = len(nums)
result = [1] * nums_size
# 累乘数字前面的数
for i in range(1, nums_size, 1):
result[i] = result[i - 1] * nums[i - 1]
temp = 1
# 累乘数字后面的数
for i in range(nums_size - 1, -1, -1):
result[i] *= temp
temp *= nums[i]
return result
s = Solution()
A = [2, 3, 4, 5, 6, 7]
print(s.productExcludeItself(A))
[2520, 1680, 1260, 1008, 840, 720]