求除自身以外数组的乘积

1813天前 · 吐槽 · 707次阅读

input = [1,2,3,4]
# output = [24,12,8,6]
input = [5,3,2,4,1]
# output = [24,40,60,30,120]
length = len(input)
a = b = []
for index in range(length):
    r=1
    for i in input[:index]:
        r *= i
    a.append(r)
    r=1
    for i in input[length-index-1:]:
        r *= i
    b.append(r)
b.reverse()
b = b + [1]
_ = b.pop(0)
# print(a)
# print(b)
print(list(map(lambda x, y: x * y, a, b)))

这种算是知道就会,不知道也很难想出来的吧?

👍 0

none

最后修改于1813天前

评论

贴吧 狗头 原神 小黄脸
收起

贴吧

狗头

原神

小黄脸

目录

avatar

未末

迷失

126

文章数

275

评论数

7

分类