question: public int [ ] productExceptSelf ( int [ ] nums ) { int n = nums . length ; int left = 1 ; int right = 1 ; int [ ] res = new int [ n ] ; Arrays . fill ( res , 1 ) ; for ( int i = 0 ; i < nums . length ; i ++ ) { res [ i ] *= left ; left *= nums [ i ] ; res [ n - 1 - i ] *= right ; right *= nums [ n - 1 - i ] ; } return res ; }
target:  The product is actually composed of two parts, the integers on the left, and integers on the right. For a naive O(n) Time, O(n) Space solution You can use two arrays to store products from the beginning and from the end. Then multiply each position in the two arrays to generate result. If we want to reduce space usage to O(1), we can just replace the two arrays with two integers.