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

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;
    }
};

 

posted @ 2017-08-03 22:54  双马尾是老公的方向盘  阅读(94)  评论(0编辑  收藏  举报