链接:https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/
代码
class Solution {
public:
vector<int> constructArr(vector<int>& a) {
if (a.empty()) return vector<int>();
int n = a.size();
vector<int> res(n);
for (int i = 0, p = 1; i < n; ++i) {
res[i] = p;
p *= a[i];
}
for (int i = n - 1, p = 1; i >= 0; --i) {
res[i] *= p;
p *= a[i];
}
return res;
}
};