这题是不让用除法,没想到别的好方法,只能想到把2边的乘起来。。。注意不要出现多次重复乘了。代码如下:
class Solution(object):
def productExceptSelf(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
list1 = [1]
for i in range(1, len(nums)):
list1.append(list1[i - 1] * nums[i - 1])
list2 = [1]
for i in range(len(nums) - 1)[::-1]:
list2.append(list2[len(nums) - 2 - i] * nums[i + 1])
for i in range(len(nums)):
nums[i] = list1[i] * list2[len(nums) - 1 - i]
return nums