class Solution {
public:
vector<int> multiply(const vector<int>& nums) {
int n=nums.size();
if(n==0) return vector<int>();
vector<int> q(n,1);
for (int i = 1,t=nums[0]; i < n; i ++ )//t记录前i个数的乘积
{
q[i]=t;
t*=nums[i];
}
for (int i = n-2,t=nums[n-1]; i >= 0; i -- )//t记录后i个数的乘积
{
q[i]*=t;
t*=nums[i];
}
return q;
}
};
标签:return,乘积,nums,int,个数,vector,构建,数组
From: https://www.cnblogs.com/tangxibomb/p/17417322.html