@@ -0,0 +1,1985 @@
+//  Copyright 2016 The Sawdust Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A//%0A%0A/**%0A * Given an array of n integers where n %3E 1, nums, return an array output such that output%5Bi%5D is equal%0A * to the product of all the elements of nums except nums%5Bi%5D.%0A * %3Cp/%3E%0A * Solve it without division and in O(n).%0A * %3Cp/%3E%0A * For example, given %5B1,2,3,4%5D, return %5B24,12,8,6%5D.%0A * %3Cp/%3E%0A * Follow up:%0A * %3Cp/%3E%0A * Could you solve it with constant space complexity?%0A * (Note: The output array does not count as extra space for the purpose of space complexity analysis.)%0A * https://leetcode.com/problems/product-of-array-except-self/%0A */%0Apublic class Leetcode238ProductOfArrayExceptSelf %7B%0A    public static int%5B%5D productExceptSelf2(int%5B%5D nums) %7B%0A        int%5B%5D r = new int%5Bnums.length%5D;%0A        for (int i = 0; i %3C r.length; i++) %7B%0A            r%5Bi%5D = 1;%0A        %7D%0A        for (int i = 0, j = nums.length - 1, lp = 1, rp = 1; i %3C nums.length; ++i, --j) %7B%0A            r%5Bi%5D *= lp;%0A            lp *= nums%5Bi%5D;%0A            r%5Bj%5D *= rp;%0A            rp *= nums%5Bj%5D;%0A        %7D%0A        return r;%0A    %7D%0A%0A    public static int%5B%5D productExceptSelf(int%5B%5D nums) %7B%0A        int%5B%5D r = new int%5Bnums.length%5D;%0A        r%5Br.length - 1%5D = 1;%0A        for (int i = r.length - 2; i %3E= 0; i--) %7B%0A            r%5Bi%5D = r%5Bi + 1%5D * nums%5Bi + 1%5D;%0A        %7D%0A        int lp = 1;%0A        for (int i = 1; i %3C r.length; i++) %7B%0A            lp *= nums%5Bi - 1%5D;%0A            r%5Bi%5D *= lp;%0A        %7D%0A        return r;%0A    %7D%0A%7D%0A%0A

Add Leetcode238ProductOfArrayExceptSelf