24. Product of Array Except Self
MediumArrays~25 min
Return an array where each element is the product of every other element in the input.
You may not use division, and the solution should run in linear time.
Examples
Example 1
- Input:
- nums = [1, 2, 3, 4]
- Output:
- [24, 12, 8, 6]
- Why:
- 24 = 2*3*4, 12 = 1*3*4, and so on.
Example 2
- Input:
- nums = [2, 3]
- Output:
- [3, 2]
Constraints
1 <= nums.length <= 1000Division is not allowed.The array may contain zeroes.