题目: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; } }