GoConqr has a new look! Let us know what you think.

Flashcards

Product of Array Except Self - Leetcode

Suhas S English 1 card

Cards in this deck (1)

  1. 1Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n). For example, given [1,2,3,4], return [24,12,8,6].class Solution {
    public int[] productExceptSelf(int[] nums) {
    int n = nums.length;
    int[] prod = new int[n];
    int temp = 1;
    for(int i = 0; i=0 ; i--){
    prod[i] = prod[i] * temp;
    temp = temp * nums[i];
    }
    return prod;
    }
    }

Information

Description
Flashcards on Product of Array Except Self - Leetcode, created by Suhas S on 24/03/2018.
Created by
Suhas S · Mar 2018
Updated
Mar 24, 2018
Views
4
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?