Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
632 B
0
Indexable
Never
class Solution {
public:
    void flush_vec(vector<int>&a){
        for(auto &i:a) cout<<i<<" ";
        cout<<"\n";
    }
    vector<int> productExceptSelf(vector<int>& nums) {
        int n=nums.size();
        vector<int>res(n);
        vector<int>fow(n,1);
        vector<int>bac(n,1);
        fow[1]=nums[0];
        bac[n-2]=nums[n-1];
        for(int i=2;i<n;i++){
            fow[i]=fow[i-1]*nums[i-1];
        }
        for(int i=n-3;i>=0;i--){
            bac[i]=bac[i+1]*nums[i+1];
        }

        //flush_vec(bac);
        for(int i=0;i<n;i++){
            res[i]=fow[i]*bac[i];
        }
        return res;
    }
};
Leave a Comment