LeetCode: Product of Array Except Self
https://leetcode.com/problems/product-of-array-except-self/description/
解题思路:
http://blog.csdn.net/wzy_1988/article/details/46916179
class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { vector<int> result(nums.size()); result[0] = 1; int p = 1; for (int i = 1; i < nums.size(); i++){ p *= nums[i-1]; result[i] = p; } p = 1; for (int i = nums.size()-2; i >= 0; i--){ p *= nums[i+1]; result[i] *= p; } return result; } };