题目描述
blablabla
样例
class Solution {
public:
vector<int> multiply(const vector<int>& A) {
//正着走一趟,反着走一趟
// 1, A[0], A[0]*A[1], A[0]*A[1]*A[2],...A[0]*A[1] *...A[n - 1];
// B[n - 1] * 1, B[n - 2] * A[n - 1] * A[n-2],...,B[0] * A[n - 1]*...A[1];
if(A.empty()) return vector<int> ();
int n = A.size();
vector<int> B(n);
for (int i = 0, tmp = 1; i < n; i ++) {
B[i] = tmp;
tmp = tmp * A[i];
}
for (int i = n - 1, tmp = 1; i >=0; i --) {
B[i] *= tmp;
tmp = tmp * A[i];
}
return B;
}
};