Product of Array Except Self(array)
Given an arraynums
ofn_integers where_n> 1, return an arrayoutput
such thatoutput[i]
is equal to the product of all the elements ofnums
exceptnums[i]
.
Example:
Note:Please solve itwithout divisionand in O(n).
Follow up: Could you solve it with constant space complexity? (The output arraydoes notcount as extra space for the purpose of space complexity analysis.)
分析
left 和right需要错位2 left -> 1,a1,a2,a3...an-2 right->a2,a3,...an-1,1这样 a1=a0*a2
注意zip 和list里2个for 的区别,前者对齐操作,后者就是2个loop交叉
左边右边同时累积乘,记得不包含当前数
左边相当于切尾,右边相当于切头
Last updated