fix 04_recursive_max on ruby
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
def max(list)
|
def max(list)
|
||||||
if list.empty?
|
return nil if list.empty?
|
||||||
nil
|
|
||||||
elsif list.length == 1
|
if list.length == 1
|
||||||
numbers[0]
|
list[0] # base case
|
||||||
else
|
else
|
||||||
sub_max = max(list[1..-1])
|
sub_max = max(list[1..-1])
|
||||||
list[0] > sub_max ? list[0] : sub_max
|
list[0] > sub_max ? list[0] : sub_max
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
puts max([2,3,8,5,5])
|
||||||
|
|||||||
Reference in New Issue
Block a user