49 ms c++


  • 0
    Z
    
    class Solution {
    public:
        vector<int> productExceptSelf(vector<int>& nums) {
            int len = nums.size();
            vector<int> output(len,1);
            
            int multiple = 1;
            for (int i=0; i<(len-1); i++) {
                multiple *= nums[i];
                output[i+1] *= multiple;
            }
            
            multiple = 1;
            for (int i=len-1; i>0; i--) {
                multiple *= nums[i];
                output[i-1] *= multiple;
            }
            return output;
        }
    };
    
    
    

Log in to reply
 

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