Flashcards
Product of Array Except Self - Leetcode
Flashcards do conjunto (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;
}
}
Informações
- Descrição
- FlashCards sobre Product of Array Except Self - Leetcode, criado por Suhas S em 24-03-2018.
- Criado por
- Suhas S · mar 2018
- Atualizado
- 24 mar 2018
- Visualizações
- 4
- Avaliação