C++ within 10 lines, O(n)-O(1)


  • 0
    P
    vector<int> productExceptSelf(vector<int>& nums) {
        vector<int> ret;
        int len = nums.size();
        int i, tmp=1;
        for(i=0;i<len;i++)ret.push_back(tmp), tmp*=nums[i];
        tmp = 1;
        for(i=len-1;i>=0;i--)ret[i]*=tmp, tmp*=nums[i];
        return ret;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.