首页 > 其他 > 详细

LeetCode: Product of Array Except Self

时间:2017-09-02 17:34:58      阅读:228      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/yxzfscg/p/7467141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!