码迷,mamicode.com
首页 > 编程语言 > 详细

剑指offer---构建乘积数组

时间:2017-08-03 23:07:57      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:int   ons   logs   剑指offer   ++   blog   tip   color   数组   

class Solution 
{
public:
    vector<int> multiply(const vector<int>& A) 
    {
        vector<int> result;
        int size = A.size();
        for (int i = 0; i < size; ++i)
        {
            int chengji=1;
            for (int j = 0; j < size; ++j)
            {
                if (i!=j    )
                {
                    chengji = chengji*A[j];
                }
            }
            result.push_back(chengji);
        }
        return result;
    }
};

 

剑指offer---构建乘积数组

标签:int   ons   logs   剑指offer   ++   blog   tip   color   数组   

原文地址:http://www.cnblogs.com/159269lzm/p/7282544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!