Problem
Code
/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/
int* productExceptSelf(int* nums, int numsSize, int* returnSize) {
*returnSize = numsSize;
int *res = (int*)malloc(sizeof(int)*numsSize);
//Record the prev numbers
for(int i=0;i<numsSize;++i)
if(!i)
res[i] = 1;
else
res[i] = res[i-1]*nums[i-1];
//Multiply the post numbers
for(int i=numsSize-1,tmp=1;i>=0;--i){
res[i] = tmp*res[i];
tmp *= nums[i];
}
return res;
}