mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-14 08:01:05 +01:00
Change condition structure
This commit is contained in:
parent
29dc653dba
commit
059d319a09
1 changed files with 2 additions and 1 deletions
|
@ -87,7 +87,7 @@ end
|
||||||
def output(prefix_products, suffix_products, nums)
|
def output(prefix_products, suffix_products, nums)
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
nums.reverse.each_with_index do |_num, index|
|
nums.count.times do |index|
|
||||||
result << if index == 0
|
result << if index == 0
|
||||||
suffix_products[index + 1]
|
suffix_products[index + 1]
|
||||||
elsif index == nums.length - 1
|
elsif index == nums.length - 1
|
||||||
|
@ -150,6 +150,7 @@ def products(nums)
|
||||||
# Note: for the element at index 'length - 1', there are no elements to the right,
|
# Note: for the element at index 'length - 1', there are no elements to the right,
|
||||||
# so the R would be 1
|
# so the R would be 1
|
||||||
product = 1
|
product = 1
|
||||||
|
|
||||||
(nums.size - 1).downto(1).each do |i|
|
(nums.size - 1).downto(1).each do |i|
|
||||||
num = nums[i]
|
num = nums[i]
|
||||||
# For the index 'i', R would contain the
|
# For the index 'i', R would contain the
|
||||||
|
|
Loading…
Reference in a new issue