mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-13 08:01:03 +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)
|
||||
result = []
|
||||
|
||||
nums.reverse.each_with_index do |_num, index|
|
||||
nums.count.times do |index|
|
||||
result << if index == 0
|
||||
suffix_products[index + 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,
|
||||
# so the R would be 1
|
||||
product = 1
|
||||
|
||||
(nums.size - 1).downto(1).each do |i|
|
||||
num = nums[i]
|
||||
# For the index 'i', R would contain the
|
||||
|
|
Loading…
Reference in a new issue