LeetCode: Product of Array Except Self

Posted 月下之风

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
    }
};

  

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

LeetCode: Product of Array Except Self

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

#leetcode#Product of Array Except Self

LeetCode-Maximum Product of Word Lengths

LeetCode 1352. Product of the Last K Numbers

leetcode:238. Product of Array Except Self(Java)解答