class Solution {
public int[] productExceptSelf(int[] nums) {
int n=nums.length;
int [] fwd=new int[n];
int [] bwd=new int[n];
int [] res=new int[n];
bwd[n-1]=1;
fwd[0]=1;
for(int i=1;i<n;i++)
{
fwd[i]=fwd[i-1]*nums[i-1];
}
for(int i=n-2;i>=0;i--)
{
bwd[i]=bwd[i+1]*nums[i+1];
}
for(int i=0;i<n;i++)
{
res[i]=fwd[i]*bwd[i];
}
return res;
}
}