美文网首页
【数组】构建乘积数组

【数组】构建乘积数组

作者: 一个想当大佬的菜鸡 | 来源:发表于2019-10-10 13:50 被阅读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

相关文章

网友评论

      本文标题:【数组】构建乘积数组

      本文链接:https://www.haomeiwen.com/subject/tzafyctx.html