mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-14 08:01:05 +01:00
Separators
This commit is contained in:
parent
13f9770de5
commit
dcfdf73a7f
1 changed files with 4 additions and 0 deletions
|
@ -5,7 +5,9 @@
|
||||||
# each element at index `i` of the new array is the product of
|
# each element at index `i` of the new array is the product of
|
||||||
# all the numbers in the original array except the one at `i`.
|
# all the numbers in the original array except the one at `i`.
|
||||||
|
|
||||||
|
#
|
||||||
# 1. Brute force solution
|
# 1. Brute force solution
|
||||||
|
#
|
||||||
def calculate_products_of_all_other_elements(nums)
|
def calculate_products_of_all_other_elements(nums)
|
||||||
products_other_elements = Array.new(nums.length, 1)
|
products_other_elements = Array.new(nums.length, 1)
|
||||||
|
|
||||||
|
@ -22,8 +24,10 @@ end
|
||||||
|
|
||||||
puts(calculate_products_of_all_other_elements([1, 2, 3]))
|
puts(calculate_products_of_all_other_elements([1, 2, 3]))
|
||||||
|
|
||||||
|
#
|
||||||
# 2. O(n) time and space
|
# 2. O(n) time and space
|
||||||
# Arrays - Get Products of all other elements in Ruby
|
# Arrays - Get Products of all other elements in Ruby
|
||||||
|
#
|
||||||
|
|
||||||
# Generates prefix products
|
# Generates prefix products
|
||||||
def build_prefix_products(nums)
|
def build_prefix_products(nums)
|
||||||
|
|
Loading…
Reference in a new issue