5-Lines Java Solution


  • -1
    O
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length, mult = nums[0], i;
        int[] res = new int[n];
        for (i = 1; i < n; mult *= nums[i++]) res[i] = mult;
        for (res[0] = 1, mult = nums[n - 1], i = n - 2; i >= 0; mult *= nums[i--]) res[i] *= mult;
        return res;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.