Create 04_recursive_max.py (#249)
Problem with max definition. If in input list last element is the biggest, the present algorithm is'n count it. I solved this problem by changing the return in the case if length == 1 from return 1 to first element of list.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
def max_(lst):
|
def max(lst):
|
||||||
if len(lst) == 0:
|
if len(lst) == 0:
|
||||||
return None
|
return None
|
||||||
if len(lst) == 1:
|
if len(lst) == 1:
|
||||||
return lst[0]
|
return lst[0]
|
||||||
else:
|
else:
|
||||||
sub_max = max_(lst[1:])
|
max_num = max(lst[1:])
|
||||||
return lst[0] if lst[0] > sub_max else sub_max
|
return lst[0] if lst[0] > max_num else max_num
|
||||||
|
|||||||
Reference in New Issue
Block a user