Product of Array Except Self

Posted RenewDo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Product of Array Except Self相关的知识,希望对你有一定的参考价值。

 

 1 class Solution {
 2 public:
 3     vector<int> productExceptSelf(vector<int>& nums) {
 4         vector<int> output(nums.size(), 1);
 5         if(nums.empty())
 6                return output;
 7         int left=1, right=1;
 8         for(int i=0; i<nums.size(); i++)
 9         {
10             output[i] = left;
11             left = left * nums[i];
12         }
13         for(int i=nums.size()-1; i>=0; i--)
14         {
15             output[i] = right * output[i];
16             right = right * nums[i];            
17         }
18         
19         return output;
20     }
21 };

 

以上是关于Product of Array Except Self的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode: Product of Array Except Self

Product of Array Except Self

238. Product of Array Except Self

238. Product of Array Except Self

LeetCode OJ 238. Product of Array Except Self 解题报告

238. Product of Array Except Self