剑指Offer66.构建乘积数组

题目:https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/

思路:从左往右遍历一遍,再从左往右遍历。

代码:

class Solution {
    public int[] constructArr(int[] a) {
        int[] b = new int[a.length];
        for(int i=0, product = 1; i<a.length; product*=a[i++]){
            b[i] = product;
        }
        for(int i=a.length-1, product = 1; i>=0; product*=a[i--]){
            b[i] *= product;
        }
        return b;
    }
}
原文地址:https://www.cnblogs.com/liuyongyu/p/14079048.html