P16323 [GeeksforGeeks] Product array puzzle4525
普及-
题目描述

Given an array nums[] of size n, construct a Product Array P (of same size n) such that P[i] is equal to the product of all the elements of nums except nums[i].

Example 1:
Input:
n = 5
nums[] = {10, 3, 5, 6, 2}
Output:
180 600 360 300 900
Explanation:
For i=0, P[i] = 3562 = 180.
For i=1, P[i] = 10
562 = 600.
For i=2, P[i] = 10362 = 360.
For i=3, P[i] = 10
352 = 300.
For i=4, P[i] = 1035*6 = 900.
Example 2:
Input:
n = 2
nums[] = {12,0}
Output:
0 12
Your Task:
You do not have to read input. Your task is to complete the function productExceptSelf() that takes array nums[] and n as input parameters and returns a list of n integers denoting the product array P. If the array has only one element the returned list should should contains one value i.e {1}
Note: Try to solve this problem without using the division operation.

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)

Constraints:
1 <= n <= 1000
0 <= nums_{i} <= 200
Array may contain duplicates.

输入格式

见题面

输出格式

见题面

样例输入
n = 5 nums[] = {10, 3, 5, 6, 2}
样例输出
180 600 360 300 900