L50 Product of Array Exclude itself
Given an array ofnintegers wheren> 1,nums
, return an arrayoutput
such thatoutput[i]
is equal to the product of all the elements ofnums
exceptnums[i]
.
Solve it without division and in O(n).
For example, given[1,2,3,4]
, return[24,12,8,6]
.
Follow up: Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)
还有一个方法是另开一个变量:
Last updated