C++简单代码/4行:

class Solution {
public:
    vector<int> multiply(const vector<int>& A) {
        vector<int> res(A.size());
        for (int i = 0, ans = 1; i < A.size(); ans *= A[i], i ++) res[i] = ans;
        for (int i = A.size() - 1, ans = 1; i >= 0; ans *= A[i], i --) res[i] *= ans;
        return res;
    }
};