Product of Array Except Self Solutions in C++Number 238Difficulty MediumAcceptance 60.2%Link LeetCodeOther languages PythonSolutionsC++ solution by haoel/leetcode// Source : https://leetcode.com/problems/product-of-array-except-self/// Author : Hao Chen// Date : 2015-07-17 class Solution {public: vector<int> productExceptSelf(vector<int>& nums) { int len = nums.size(); vector<int> result(len, 1); //from the left to right for (int i=1; i<len; i++) { result[i] = result[i-1]*nums[i-1]; } //from the right to left int factorial = 1; for (int i=len-2; i>=0; i--){ factorial *= nums[i+1]; result[i] *= factorial; } return result; }};// Source : https://leetcode.com/problems/product-of-array-except-self/ // Author : Hao Chen // Date : 2015-07-17 class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { int len = nums.size(); vector<int> result(len, 1); //from the left to right for (int i=1; i<len; i++) { result[i] = result[i-1]*nums[i-1]; } //from the right to left int factorial = 1; for (int i=len-2; i>=0; i--){ factorial *= nums[i+1]; result[i] *= factorial; } return result; } };