mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +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
|
||||
# all the numbers in the original array except the one at `i`.
|
||||
|
||||
#
|
||||
# 1. Brute force solution
|
||||
#
|
||||
def calculate_products_of_all_other_elements(nums)
|
||||
products_other_elements = Array.new(nums.length, 1)
|
||||
|
||||
|
@ -22,8 +24,10 @@ end
|
|||
|
||||
puts(calculate_products_of_all_other_elements([1, 2, 3]))
|
||||
|
||||
#
|
||||
# 2. O(n) time and space
|
||||
# Arrays - Get Products of all other elements in Ruby
|
||||
#
|
||||
|
||||
# Generates prefix products
|
||||
def build_prefix_products(nums)
|
||||
|
|
Loading…
Reference in a new issue