构建乘积数组
构建乘积数组
http://www.nowcoder.com/questionTerminal/94a4d381a68b47b7a8bed86f2975db46
看到大神的思路,不禁膜拜!牛!
vector<int> multiply(const vector<int>& A) { int len = A.size(); vector<int>res; res.push_back(1); for(int i=1;i<len;i++) { int t = res[i-1]*A[i-1]; res.push_back(t); } int tmp=1; for(int j=len-2;j>=0;j--) { tmp*=A[j+1]; res[j]*=tmp; } return res; }